Merge pull request #731 from huanggze/master
Improve API error handling
This commit is contained in:
commit
70a94c09a1
|
@ -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{
|
err = &Error{
|
||||||
Type: ErrBadResponse,
|
Type: ErrBadResponse,
|
||||||
Msg: "inconsistent body for response code",
|
Msg: "inconsistent body for response code",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiError(code) && result.Status == "error" {
|
if result.Status == "error" {
|
||||||
err = &Error{
|
err = &Error{
|
||||||
Type: result.ErrorType,
|
Type: result.ErrorType,
|
||||||
Msg: result.Error,
|
Msg: result.Error,
|
||||||
|
|
|
@ -1095,8 +1095,8 @@ func TestAPIClientDo(t *testing.T) {
|
||||||
Error: "timed out",
|
Error: "timed out",
|
||||||
},
|
},
|
||||||
expectedErr: &Error{
|
expectedErr: &Error{
|
||||||
Type: ErrBadResponse,
|
Type: ErrTimeout,
|
||||||
Msg: "inconsistent body for response code",
|
Msg: "timed out",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1109,8 +1109,8 @@ func TestAPIClientDo(t *testing.T) {
|
||||||
Warnings: []string{"a"},
|
Warnings: []string{"a"},
|
||||||
},
|
},
|
||||||
expectedErr: &Error{
|
expectedErr: &Error{
|
||||||
Type: ErrBadResponse,
|
Type: ErrTimeout,
|
||||||
Msg: "inconsistent body for response code",
|
Msg: "timed out",
|
||||||
},
|
},
|
||||||
expectedWarnings: []string{"a"},
|
expectedWarnings: []string{"a"},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue