-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
53 lines (48 loc) · 1.47 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
44
45
46
47
48
49
50
51
52
53
package groupme
import (
"errors"
"net/http"
)
// StatusEnhanceYourCalm is "returned when you are being rate limited. Chill the heck out."
const StatusEnhanceYourCalm = 420
// Errors returned by GroupMe.
var (
ErrNotModified = errors.New("304 Not Modified")
ErrBadRequest = errors.New("400 Bad Request")
ErrUnauthorized = errors.New("401 Unauthorized")
ErrForbidden = errors.New("403 Forbidden")
ErrNotFound = errors.New("404 Not Found")
ErrEnhanceYourCalm = errors.New("420 Enhance Your Calm")
ErrInternalServerError = errors.New("500 Internal Server Error")
ErrBadGateway = errors.New("502 Bad Gateway")
ErrServiceUnavailable = errors.New("503 Service Unavailable")
)
// Meta is the error response from the GroupMe API.
type Meta struct {
Code int `json:"code"`
Errors []string `json:"errors"`
}
func parseError(statusCode int, status string) error {
switch statusCode {
case http.StatusNotModified:
return ErrNotModified
case http.StatusBadRequest:
return ErrBadRequest
case http.StatusUnauthorized:
return ErrUnauthorized
case http.StatusForbidden:
return ErrForbidden
case http.StatusNotFound:
return ErrNotFound
case StatusEnhanceYourCalm:
return ErrEnhanceYourCalm
case http.StatusInternalServerError:
return ErrInternalServerError
case http.StatusBadGateway:
return ErrBadGateway
case http.StatusServiceUnavailable:
return ErrServiceUnavailable
default:
return errors.New(status)
}
}