File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,16 @@ func (e StatusError) StatusCode() int {
4141 return e .resp .StatusCode
4242}
4343
44+ // HasStatus returns true if the respose's status code matches any of the given codes
45+ func (e StatusError ) HasStatus (codes ... int ) bool {
46+ for _ , code := range codes {
47+ if e .resp .StatusCode == code {
48+ return true
49+ }
50+ }
51+ return false
52+ }
53+
4454// ReadBody reads HTTP response and returns error on response codes other than HTTP 2xx
4555func ReadBody (resp * http.Response ) ([]byte , error ) {
4656 defer resp .Body .Close ()
Original file line number Diff line number Diff line change @@ -293,8 +293,8 @@ func (v *API) getStatus() (float64, error) {
293293 err = v .DoJSON (req , & resp )
294294
295295 if err != nil {
296- resp := v . LastResponse ()
297- if resp != nil && resp . StatusCode == http .StatusForbidden {
296+ // handle http 401, 403
297+ if se , ok := err .(request. StatusError ); ok && se . HasStatus ( http . StatusUnauthorized , http .StatusForbidden ) {
298298 err = errAuthFail
299299 }
300300 }
You can’t perform that action at this time.
0 commit comments