diff --git a/myhttp/fasthttpc/httpclient.go b/myhttp/fasthttpc/httpclient.go index 917b4c2..c577e27 100644 --- a/myhttp/fasthttpc/httpclient.go +++ b/myhttp/fasthttpc/httpclient.go @@ -324,8 +324,12 @@ func (r *Request) doRequest(timeout time.Duration, method, rawUrl string) (*Resp copy(body, tmpBody) if r.httpClient.config.noCheckStatus == false { - if resp.StatusCode() != http.StatusOK { - return nil, fmt.Errorf("status code err: %d (%s)", resp.StatusCode(), body) + if resp.StatusCode() >= 400 { + return nil, &StatusErr{ + StatusCode: resp.StatusCode(), + Body: body, + } + //return nil, fmt.Errorf("status code err: %d (%s)", resp.StatusCode(), body) } } @@ -364,3 +368,14 @@ type Response struct { func (r *Response) GetBody() []byte { return r.body } + +var _ error = (*StatusErr)(nil) + +type StatusErr struct { + StatusCode int + Body []byte +} + +func (s *StatusErr) Error() string { + return fmt.Sprintf("status code err: %d (%s)", s.StatusCode, s.Body) +}