Skip to content

Commit

Permalink
avoid panic when invoke Response if error happened
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed May 12, 2022
1 parent f73e2f3 commit 64b3c41
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@ type Response struct {

// IsSuccess method returns true if HTTP status `code >= 200 and <= 299` otherwise false.
func (r *Response) IsSuccess() bool {
if r.Response == nil {
return false
}
return r.StatusCode > 199 && r.StatusCode < 300
}

// IsError method returns true if HTTP status `code >= 400` otherwise false.
func (r *Response) IsError() bool {
if r.Response == nil {
return false
}
return r.StatusCode > 399
}

// GetContentType return the `Content-Type` header value.
func (r *Response) GetContentType() string {
if r.Response == nil {
return ""
}
return r.Header.Get(hdrContentTypeKey)
}

Expand Down

0 comments on commit 64b3c41

Please sign in to comment.