forked from mirror/client_golang
Improve API error handling
Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
parent
aa9238db67
commit
8f87c69651
|
@ -905,14 +905,14 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
|
|||
}
|
||||
}
|
||||
|
||||
if apiError(code) != (result.Status == "error") {
|
||||
if apiError(code) && result.Status == "success" {
|
||||
err = &Error{
|
||||
Type: ErrBadResponse,
|
||||
Msg: "inconsistent body for response code",
|
||||
}
|
||||
}
|
||||
|
||||
if apiError(code) && result.Status == "error" {
|
||||
if result.Status == "error" {
|
||||
err = &Error{
|
||||
Type: result.ErrorType,
|
||||
Msg: result.Error,
|
||||
|
|
|
@ -1095,8 +1095,8 @@ func TestAPIClientDo(t *testing.T) {
|
|||
Error: "timed out",
|
||||
},
|
||||
expectedErr: &Error{
|
||||
Type: ErrBadResponse,
|
||||
Msg: "inconsistent body for response code",
|
||||
Type: ErrTimeout,
|
||||
Msg: "timed out",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -1109,8 +1109,8 @@ func TestAPIClientDo(t *testing.T) {
|
|||
Warnings: []string{"a"},
|
||||
},
|
||||
expectedErr: &Error{
|
||||
Type: ErrBadResponse,
|
||||
Msg: "inconsistent body for response code",
|
||||
Type: ErrTimeout,
|
||||
Msg: "timed out",
|
||||
},
|
||||
expectedWarnings: []string{"a"},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue