forked from koofr/go-httpclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
38 lines (32 loc) Β· 853 Bytes
/
errors.go
File metadata and controls
38 lines (32 loc) Β· 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package httpclient
import (
"errors"
"fmt"
"net/http"
)
type InvalidStatusError struct {
Expected []int
Got int
Headers http.Header
Content string
}
func (e InvalidStatusError) Error() string {
return fmt.Sprintf("Invalid response status! Got %d, expected %d; headers: %s, content: %s", e.Got, e.Expected, e.Headers, e.Content)
}
func IsInvalidStatusError(err error) (invalidStatusError *InvalidStatusError, ok bool) {
if ise, ok := err.(InvalidStatusError); ok {
return &ise, true
} else if ise, ok := err.(*InvalidStatusError); ok {
return ise, true
} else {
return nil, false
}
}
func IsInvalidStatusCode(err error, statusCode int) bool {
if ise, ok := IsInvalidStatusError(err); ok {
return ise.Got == statusCode
} else {
return false
}
}
var RateLimitTimeoutError = errors.New("HTTPClient rate limit timeout")