Skip to content

Commit 577ca8c

Browse files
committed
feat(errors): add TooManyRequests error type
1 parent fb8e43e commit 577ca8c

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ go.work.sum
2626
# OS General
2727
Thumbs.db
2828
.DS_Store
29+
.cache
2930

3031
# project
3132
*.cert

errors/types.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ func IsConflict(err error) bool {
5656
return Code(err) == 409
5757
}
5858

59+
// TooManyRequests new TooManyRequests error that is mapped to an HTTP 429 response.
60+
func TooManyRequests(reason, message string) *Error {
61+
return New(429, reason, message)
62+
}
63+
64+
// IsTooManyRequests determines if err is an error which indicates a TooManyRequests error.
65+
// It supports wrapped errors.
66+
func IsTooManyRequests(err error) bool {
67+
return Code(err) == 429
68+
}
69+
70+
// ClientClosed new ClientClosed error that is mapped to an HTTP 499 response.
71+
func ClientClosed(reason, message string) *Error {
72+
return New(499, reason, message)
73+
}
74+
75+
// IsClientClosed determines if err is an error which indicates a IsClientClosed error.
76+
// It supports wrapped errors.
77+
func IsClientClosed(err error) bool {
78+
return Code(err) == 499
79+
}
80+
5981
// InternalServer new InternalServer error that is mapped to a 500 response.
6082
func InternalServer(reason, message string) *Error {
6183
return New(500, reason, message)
@@ -88,14 +110,3 @@ func GatewayTimeout(reason, message string) *Error {
88110
func IsGatewayTimeout(err error) bool {
89111
return Code(err) == 504
90112
}
91-
92-
// ClientClosed new ClientClosed error that is mapped to an HTTP 499 response.
93-
func ClientClosed(reason, message string) *Error {
94-
return New(499, reason, message)
95-
}
96-
97-
// IsClientClosed determines if err is an error which indicates a IsClientClosed error.
98-
// It supports wrapped errors.
99-
func IsClientClosed(err error) bool {
100-
return Code(err) == 499
101-
}

0 commit comments

Comments
 (0)