mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
Merge pull request #13863 from ioito/hotfix/qx-service-err
fix(apigateway): convert net err to service error
This commit is contained in:
+3984
-3904
File diff suppressed because it is too large
Load Diff
+2819
-2567
File diff suppressed because it is too large
Load Diff
@@ -93,6 +93,8 @@ const (
|
||||
ErrWrongPassword = errors.Error("WrongPassword")
|
||||
ErrIncorrectUsernameOrPassword = errors.Error("IncorrectUsernameOrPassword")
|
||||
|
||||
ErrServiceAbnormal = errors.Error("ServiceAbnormal")
|
||||
|
||||
ErrInvalidAccessKey = errors.Error("InvalidAccessKey")
|
||||
ErrNoPermission = errors.Error("NoPermission")
|
||||
)
|
||||
@@ -177,6 +179,8 @@ var (
|
||||
ErrPolicyDefinition: 409,
|
||||
|
||||
ErrInvalidAccessKey: 400,
|
||||
|
||||
ErrServiceAbnormal: 499,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -208,6 +208,10 @@ func NewTooLargeEntityError(msg string, params ...interface{}) *httputils.JSONCl
|
||||
return httputils.NewJsonClientError(httpErrorCode[ErrTooLarge], string(ErrTooLarge), msg, params...)
|
||||
}
|
||||
|
||||
func NewServiceAbnormalError(msg string, params ...interface{}) *httputils.JSONClientError {
|
||||
return httputils.NewJsonClientError(httpErrorCode[ErrServiceAbnormal], string(ErrServiceAbnormal), msg, params...)
|
||||
}
|
||||
|
||||
func NewJsonClientError(err errors.Error, msg string, params ...interface{}) *httputils.JSONClientError {
|
||||
code, ok := httpErrorCode[err]
|
||||
if !ok {
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
@@ -84,9 +86,25 @@ func (this *BaseManager) versionedURL(path string) string {
|
||||
func (this *BaseManager) jsonRequest(session *mcclient.ClientSession,
|
||||
method httputils.THttpMethod, path string,
|
||||
header http.Header, body jsonutils.JSONObject) (http.Header, jsonutils.JSONObject, error) {
|
||||
return session.JSONVersionRequest(this.serviceType, this.endpointType,
|
||||
hdr, resp, err := session.JSONVersionRequest(this.serviceType, this.endpointType,
|
||||
method, this.versionedURL(path),
|
||||
header, body, this.GetApiVersion())
|
||||
if err != nil {
|
||||
if e, ok := err.(*httputils.JSONClientError); ok {
|
||||
switch e.Class {
|
||||
case errors.ErrConnectRefused.Error():
|
||||
return nil, nil, httperrors.NewServiceAbnormalError("%s service is abnormal, please check service status", this.serviceType)
|
||||
case errors.ErrNetwork.Error():
|
||||
return nil, nil, httperrors.NewServiceAbnormalError("%s service is abnormal or network error, please try again", this.serviceType)
|
||||
case errors.ErrDNS.Error():
|
||||
return nil, nil, httperrors.NewServiceAbnormalError("%s service dns resolve error, please check dns setting", this.serviceType)
|
||||
case errors.ErrTimeout.Error():
|
||||
return nil, nil, httperrors.NewServiceAbnormalError("%s service request timeout, please try again later", this.serviceType)
|
||||
}
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
return hdr, resp, nil
|
||||
}
|
||||
|
||||
func (this *BaseManager) rawRequest(session *mcclient.ClientSession,
|
||||
@@ -173,7 +191,6 @@ func JSON2ListResult(result jsonutils.JSONObject) *ListResult {
|
||||
|
||||
func (this *BaseManager) _list(session *mcclient.ClientSession, path, responseKey string) (*ListResult, error) {
|
||||
_, body, err := this.jsonRequest(session, "GET", path, nil, nil)
|
||||
// log.Debugf("%#v %#v %#v", body, err, responseKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user