-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
91 lines (77 loc) · 1.71 KB
/
errors.go
File metadata and controls
91 lines (77 loc) · 1.71 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package ipgeolocation
import "fmt"
type ValidationError struct {
Message string
}
func (e *ValidationError) Error() string {
return e.Message
}
type TransportError struct {
Message string
Err error
}
func (e *TransportError) Error() string {
return e.Message
}
func (e *TransportError) Unwrap() error {
return e.Err
}
type RequestTimeoutError struct {
TransportError
}
type SerializationError struct {
Message string
Err error
}
func (e *SerializationError) Error() string {
return e.Message
}
func (e *SerializationError) Unwrap() error {
return e.Err
}
type APIError struct {
StatusCode int
Message string
}
func (e *APIError) Error() string {
return e.Message
}
type BadRequestError struct{ APIError }
type UnauthorizedError struct{ APIError }
type ForbiddenError struct{ APIError }
type NotFoundError struct{ APIError }
type MethodNotAllowedError struct{ APIError }
type ContentTooLargeError struct{ APIError }
type UnsupportedMediaTypeError struct{ APIError }
type LockedError struct{ APIError }
type TooManyRequestsError struct{ APIError }
type CustomStatus499Error struct{ APIError }
type InternalServerError struct{ APIError }
func apiErrorMessage(statusCode int) string {
switch statusCode {
case 400:
return "Bad request"
case 401:
return "Unauthorized"
case 403:
return "Forbidden"
case 404:
return "Not found"
case 405:
return "Method not allowed"
case 413:
return "Content too large"
case 415:
return "Unsupported media type"
case 423:
return "Locked"
case 429:
return "Too many requests"
case 499:
return "Client closed request"
case 500:
return "Internal server error"
default:
return fmt.Sprintf("API request failed with status code %d", statusCode)
}
}