1
1
<p align =" center " ><img src =" https://user-images.githubusercontent.com/1092882/87815217-d864a680-c882-11ea-9c94-24b67f7125fe.png " alt =" errors gopher " width =" 256px " /></p >
2
2
3
- [ ![ ] ( https://godoc.org/github.com/nathany/looper?status.svg )] ( https://pkg.go.dev/github.com/bnkamalesh/errors?tab=doc )
4
- [ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/a86629ab167695d4db7f/maintainability )] ( https://codeclimate.com/github/bnkamalesh/errors )
5
- [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/bnkamalesh/errors )] ( https://goreportcard.com/report/github.com/bnkamalesh/errors )
6
3
[ ![ Build Status] ( https://travis-ci.org/bnkamalesh/errors.svg?branch=master )] ( https://travis-ci.org/bnkamalesh/errors )
7
4
[ ![ codecov] ( https://codecov.io/gh/bnkamalesh/errors/branch/master/graph/badge.svg )] ( https://codecov.io/gh/bnkamalesh/errors )
5
+ [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/bnkamalesh/errors )] ( https://goreportcard.com/report/github.com/bnkamalesh/errors )
6
+ [ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/a86629ab167695d4db7f/maintainability )] ( https://codeclimate.com/github/bnkamalesh/errors )
7
+ [ ![ ] ( https://godoc.org/github.com/nathany/looper?status.svg )] ( https://pkg.go.dev/github.com/bnkamalesh/errors?tab=doc )
8
8
9
9
# Errors
10
10
@@ -16,6 +16,10 @@ Errors package is a drop-in replacement of the built-in Go errors package with n
16
16
17
17
In case of nested errors, the messages (in case of nesting with this package's error) & errors are also looped through.
18
18
19
+ ### Prerequisites
20
+
21
+ Go 1.13+
22
+
19
23
### Custom error types
20
24
21
25
1 . TypeInternal - is the error type for when there is an internal system error. e.g. Database errors
@@ -78,7 +82,6 @@ package main
78
82
79
83
import (
80
84
" fmt"
81
- " log"
82
85
" net/http"
83
86
" time"
84
87
@@ -111,7 +114,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
111
114
err := foo ()
112
115
if err != nil {
113
116
// log the error on your server for troubleshooting
114
- log .Println (err.Error ())
117
+ fmt .Println (err.Error ())
115
118
// respond to request with friendly msg
116
119
status , msg , _ := errors.HTTPStatusCodeMessage (err)
117
120
webgo.SendError (w, msg, status)
@@ -155,7 +158,12 @@ Since we get the status code and message separately, when using any web framewor
155
158
Once the app is running, you can check the response by opening ` http://localhost:8080 ` on your browser. Or on terminal
156
159
``` bash
157
160
$ curl http://localhost:8080
158
- {" errors" :" we lost bar2!. bar2 was deceived by bar1 :(" ," status" :500} // output/response
161
+ {" errors" :" we lost bar2!. bar2 was deceived by bar1 :(" ," status" :500} // HTTP response
162
+ ```
163
+
164
+ And output of the ` fmt.Println(err.Error()) `
165
+ ``` bash
166
+ /Users/username/go/src/errorscheck/main.go:28 /Users/username/go/src/errorscheck/main.go:20 sinking bar
159
167
```
160
168
161
169
## Contributing
0 commit comments