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
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Errors package is a drop-in replacement of the built-in Go errors package with n
18
18
5. Helper functions to generate each error type
19
19
6. Helper function to get error Type, error type as int, check if error type is wrapped anywhere in chain
20
20
21
-
In case of nested errors, the messages (in case of nesting with this package's error) & errors are also looped through the full chain of errors.
21
+
In case of nested errors, the messages & errors are also looped through the full chain of errors.
22
22
23
23
### Prerequisites
24
24
@@ -88,7 +88,7 @@ If error is nested with multiple errors, it loops through all the levels and ret
88
88
89
89
Before that, over the years I have tried error with stack trace, annotation, custom error package with error codes etc. Finally, I think this package gives the best of all worlds, for most generic usecases.
90
90
91
-
A sample was already shown in the user friendly message section, following one would show 1-2 scenarios.
91
+
A sample was already shown in the user friendly message section, following one would show a few more scenarios.
92
92
93
93
```golang
94
94
package main
@@ -165,16 +165,16 @@ func main() {
165
165
166
166
```
167
167
168
-
[webgo](https://github.com/bnkamalesh/webgo) was used to illustrate the usage of the function, `errors.HTTPStatusCodeMessage`. It returns the appropriate http status code, user friendly message stored within, and a boolean value. Boolean value is `true` if the returned error is of this package's error type.
168
+
[webgo](https://github.com/bnkamalesh/webgo) was used to illustrate the usage of the function, `errors.HTTPStatusCodeMessage`. It returns the appropriate http status code, user friendly message stored within, and a boolean value. Boolean value is `true` if the returned error of type*Error.
169
169
Since we get the status code and message separately, when using any web framework, you can set values according to the respective framework's native functions. In case of Webgo, it wraps errors in a struct of its own. Otherwise, you could directly respond to the HTTP request by calling `errors.WriteHTTP(error,http.ResponseWriter)`.
170
170
171
171
Once the app is running, you can check the response by opening `http://localhost:8080` on your browser. Or on terminal
172
172
```bash
173
173
$ curl http://localhost:8080
174
-
{"errors":"we lost bar2!. bar2 was deceived by bar1 :(","status":500} // HTTP response
174
+
{"errors":"we lost bar2!. bar2 was deceived by bar1 :(","status":500} // output
175
175
```
176
176
177
-
And output of the `fmt.Println(err.Error())`
177
+
And the `fmt.Println(err.Error())` generated output on stdout would be:
178
178
```bash
179
179
/Users/username/go/src/errorscheck/main.go:28 /Users/username/go/src/errorscheck/main.go:20 sinking bar
0 commit comments