21
pkg/gojenkins/utils/utils.go
Normal file
21
pkg/gojenkins/utils/utils.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/asaskevich/govalidator"
|
||||
"kubesphere.io/kubesphere/pkg/gojenkins"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetJenkinsStatusCode(jenkinsErr error) int {
|
||||
if code, err := strconv.Atoi(jenkinsErr.Error()); err == nil {
|
||||
message := http.StatusText(code)
|
||||
if !govalidator.IsNull(message) {
|
||||
return code
|
||||
}
|
||||
}
|
||||
if jErr, ok := jenkinsErr.(*gojenkins.ErrorResponse); ok {
|
||||
return jErr.Response.StatusCode
|
||||
}
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
Reference in New Issue
Block a user