You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-5Lines changed: 69 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,28 +7,28 @@ This package holds helpers for better error handling, adding wrapped and context
7
7
### `ApplicationError`
8
8
9
9
A generic application error, as a failure in parametrization or other unexpected error.
10
-
*This error usually translates to a HTTP **503 Service Unavailable** error.*
10
+
_This error usually translates to a HTTP **503 Service Unavailable** error._
11
11
12
12
### `ConflictError`
13
13
14
14
Indicates an action is conflicting with another action, as for example duplicated requests.
15
-
*This error usually translates to a HTTP **429 Conflict** error.*
15
+
_This error usually translates to a HTTP **429 Conflict** error._
16
16
17
17
### `ForbiddenError`
18
18
19
19
Indicates an action is not allowed, even if authenticated.
20
-
*This error usually translates to a HTTP **403 Forbidden** error.*
20
+
_This error usually translates to a HTTP **403 Forbidden** error._
21
21
22
22
### `NotAuthorizedError`
23
23
24
24
Indicates an action needs authorization or authentication to proceed.
25
-
*This error usually translated to a HTTP **401 Unauthorized** error.*
25
+
_This error usually translated to a HTTP **401 Unauthorized** error._
26
26
27
27
### `ValidationError`
28
28
29
29
Indicates that a parameter provided is not in the correct format or not present if required.
30
30
This error allows to set a property that is related to the error and also add sub validation errors to build a validation error chain.
31
-
*This error usually translates to a HTTP **422 Unprocessable Entity** error.*
31
+
_This error usually translates to a HTTP **422 Unprocessable Entity** error._
32
32
33
33
> **Note:** All error constructors return a wrapped version of the error, removing the need to always pair an error constructor with a call to `errors.Wrap`.
34
34
@@ -91,6 +91,26 @@ func Main() {
91
91
}
92
92
```
93
93
94
+
### `Wrapf(err error, format string, args ...interface{}) error`
95
+
96
+
Same as `Wrap` but accepts a format string
97
+
98
+
**Example:**
99
+
100
+
```go
101
+
response:= service.MakeHttpRequest()
102
+
if response.StatusCode != http.StatusOK {
103
+
return errors.Wrapf(`
104
+
unexpected http response status.
105
+
expected: %d
106
+
got: %d
107
+
`,
108
+
http.StatusOK,
109
+
response.StatusCode,
110
+
)
111
+
}
112
+
```
113
+
94
114
## `GetOriginalError(err error) error`
95
115
96
116
There is a utility method to retrieve the original error from a chain of wrapped errors:
@@ -105,3 +125,47 @@ if originalErr == sql.ErrNoRows {
0 commit comments