|
5 | 5 | "bytes" |
6 | 6 | "fmt" |
7 | 7 | "io" |
8 | | - "net/http" |
9 | 8 | "runtime" |
10 | 9 | "strconv" |
11 | 10 | "strings" |
@@ -42,6 +41,15 @@ const ( |
42 | 41 | TypeSubscriptionExpired |
43 | 42 | // TypeDownstreamDependencyTimedout is error type for when a request to a downstream dependent service times out |
44 | 43 | TypeDownstreamDependencyTimedout |
| 44 | + // TypeNotImplemented is error type for when the requested function cannot be fullfilled because of incapability |
| 45 | + TypeNotImplemented |
| 46 | + // TypeContextTimedout is error type for when the Go context has timed out |
| 47 | + TypeContextTimedout |
| 48 | + // TypeContextCancelled is error type for when the Go context has been cancelled |
| 49 | + TypeContextCancelled |
| 50 | +) |
| 51 | + |
| 52 | +const ( |
45 | 53 |
|
46 | 54 | // DefaultMessage is the default user friendly message |
47 | 55 | DefaultMessage = "unknown error occurred" |
@@ -164,54 +172,11 @@ func (e *Error) Is(err error) bool { |
164 | 172 | return o == e |
165 | 173 | } |
166 | 174 |
|
167 | | -// HTTPStatusCode is a convenience method used to get the appropriate HTTP response status code for the respective error type |
| 175 | +// Deprecated: HTTPStatusCode is a convenience method used to get the appropriate |
| 176 | +// HTTP response status code for the respective error type. |
| 177 | +// deprecated to free the Error type from protocol specific features |
168 | 178 | func (e *Error) HTTPStatusCode() int { |
169 | | - status := http.StatusInternalServerError |
170 | | - switch e.eType { |
171 | | - case TypeValidation: |
172 | | - { |
173 | | - status = http.StatusUnprocessableEntity |
174 | | - } |
175 | | - case TypeInputBody: |
176 | | - { |
177 | | - status = http.StatusBadRequest |
178 | | - } |
179 | | - |
180 | | - case TypeDuplicate: |
181 | | - { |
182 | | - status = http.StatusConflict |
183 | | - } |
184 | | - |
185 | | - case TypeUnauthenticated: |
186 | | - { |
187 | | - status = http.StatusUnauthorized |
188 | | - } |
189 | | - case TypeUnauthorized: |
190 | | - { |
191 | | - status = http.StatusForbidden |
192 | | - } |
193 | | - |
194 | | - case TypeEmpty: |
195 | | - { |
196 | | - status = http.StatusGone |
197 | | - } |
198 | | - |
199 | | - case TypeNotFound: |
200 | | - { |
201 | | - status = http.StatusNotFound |
202 | | - |
203 | | - } |
204 | | - case TypeMaximumAttempts: |
205 | | - { |
206 | | - status = http.StatusTooManyRequests |
207 | | - } |
208 | | - case TypeSubscriptionExpired: |
209 | | - { |
210 | | - status = http.StatusPaymentRequired |
211 | | - } |
212 | | - } |
213 | | - |
214 | | - return status |
| 179 | + return httpStatusCode(e.eType) |
215 | 180 | } |
216 | 181 |
|
217 | 182 | // Type returns the error type as integer |
@@ -339,14 +304,14 @@ func New(msg string) *Error { |
339 | 304 | return newerr(nil, msg, defaultErrType, 3) |
340 | 305 | } |
341 | 306 |
|
342 | | -func Newf(fromat string, args ...interface{}) *Error { |
| 307 | +func Newf(fromat string, args ...any) *Error { |
343 | 308 | return newerrf(nil, defaultErrType, 4, fromat, args...) |
344 | 309 | } |
345 | 310 |
|
346 | 311 | // Errorf is a convenience method to create a new instance of Error with formatted message |
347 | 312 | // Important: %w directive is not supported, use fmt.Errorf if you're using the %w directive or |
348 | 313 | // use Wrap/Wrapf to wrap an error. |
349 | | -func Errorf(fromat string, args ...interface{}) *Error { |
| 314 | +func Errorf(fromat string, args ...any) *Error { |
350 | 315 | return newerrf(nil, defaultErrType, 4, fromat, args...) |
351 | 316 | } |
352 | 317 |
|
|
0 commit comments