-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
43 lines (38 loc) · 1.11 KB
/
errors.go
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
39
40
41
42
43
package qbittorrent_api
import (
"github.com/pkg/errors"
"net/http"
)
var (
//ErrMissingRequiredParameters = errors.New("MissingRequiredParameters")
ErrInvalidRequest = errors.New("InvalidRequest")
ErrUnauthorized = errors.New("Unauthorized")
ErrForbidden = errors.New("Forbidden")
ErrNotFound = errors.New("NotFound")
ErrMethodNotAllowed = errors.New("MethodNotAllowed")
ErrConflict = errors.New("Conflict")
ErrUnsupportedMediaType = errors.New("UnsupportedMediaType")
ErrInternalServerError = errors.New("InternalServerError")
)
func handleResponsesErr(statusCode int) error {
if statusCode < 400 {
return nil
}
switch statusCode {
case http.StatusBadRequest:
return ErrInvalidRequest
case http.StatusUnauthorized:
return ErrUnauthorized
case http.StatusForbidden:
return ErrForbidden
case http.StatusNotFound:
return ErrNotFound
case http.StatusMethodNotAllowed:
return ErrMethodNotAllowed
case http.StatusConflict:
return ErrConflict
case http.StatusUnsupportedMediaType:
return ErrUnsupportedMediaType
}
return ErrInternalServerError
}