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
Helper functions are available for all the error types. Each of them have 2 helper functions, one which accepts only a string,
47
47
and the other which accepts an original error as well as a user friendly message.
48
48
49
-
All the dedicated error type functions are documented [here](https://pkg.go.dev/github.com/bnkamalesh/errors?tab=doc#DownstreamDependencyTimedout).
49
+
All the dedicated error type functions are documented [here](https://pkg.go.dev/github.com/naughtygopher/errors?tab=doc#DownstreamDependencyTimedout).
50
50
Names are consistent with the error type, e.g. errors.Internal(string) and errors.InternalErr(error, string)
51
51
52
52
### User friendly messages
@@ -63,7 +63,7 @@ package main
63
63
import (
64
64
"fmt"
65
65
66
-
"github.com/bnkamalesh/errors"
66
+
"github.com/naughtygopher/errors"
67
67
)
68
68
69
69
funcBar() error {
@@ -99,10 +99,10 @@ Output
99
99
```
100
100
err: bar is not happy
101
101
102
-
err.Error(): /Users/k.balakumaran/go/src/github.com/bnkamalesh/errors/cmd/main.go:16: bar is not happy
102
+
err.Error(): /Users/k.balakumaran/go/src/github.com/naughtygopher/errors/cmd/main.go:16: bar is not happy
103
103
hello world!bar is not happy
104
104
105
-
formatted +v: /Users/k.balakumaran/go/src/github.com/bnkamalesh/errors/cmd/main.go:16: bar is not happy
105
+
formatted +v: /Users/k.balakumaran/go/src/github.com/naughtygopher/errors/cmd/main.go:16: bar is not happy
[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.
205
+
[webgo](https://github.com/naughtygopher/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.
206
206
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)`.
207
207
208
208
Once the app is running, you can check the response by opening `http://localhost:8080` on your browser. Or on terminal
@@ -229,7 +229,7 @@ go version go1.19.5 darwin/amd64
0 commit comments