-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patherrors.go
43 lines (36 loc) · 878 Bytes
/
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 fixer
import "net/http"
// NewError creates a new Error
func NewError(msg string) *Error {
return &Error{msg: msg}
}
// Error type for Fixer API requests
type Error struct {
msg string
}
// Error message
func (e *Error) Error() string {
return e.msg
}
// Errors
var (
ErrNilResponse = NewError("Unexpected nil response")
ErrUnexpectedStatus = NewError("Unexpected status")
ErrNotFound = NewError(http.StatusText(http.StatusNotFound))
ErrUnprocessableEntity = NewError(http.StatusText(http.StatusUnprocessableEntity))
)
func responseError(resp *http.Response) error {
if resp == nil {
return ErrNilResponse
}
switch resp.StatusCode {
case http.StatusOK:
return nil
case http.StatusNotFound:
return ErrNotFound
case http.StatusUnprocessableEntity:
return ErrUnprocessableEntity
default:
return ErrUnexpectedStatus
}
}