File tree 3 files changed +21
-1
lines changed
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "net/http"
4
+
5
+ func handlerErr (w http.ResponseWriter , r * http.Request ) {
6
+ respondWithError (w , 400 , "something went wrong" )
7
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,18 @@ import (
6
6
"net/http"
7
7
)
8
8
9
+ func respondWithError (w http.ResponseWriter , code int , msg string ) {
10
+ if code > 499 {
11
+ log .Println ("Error with the response 5XX :" , msg )
12
+ }
13
+ type errResponse struct {
14
+ Error string `json:"error"`
15
+ }
16
+ respondWithJson (w , code , errResponse {
17
+ Error : msg ,
18
+ })
19
+ }
20
+
9
21
func respondWithJson (w http.ResponseWriter , code int , payload interface {}) {
10
22
dat , err := json .Marshal (payload )
11
23
if err != nil {
Original file line number Diff line number Diff line change @@ -27,7 +27,8 @@ func main() {
27
27
}))
28
28
29
29
v1Router := chi .NewRouter ()
30
- v1Router .HandleFunc ("/healtz" , handlerReadiness )
30
+ v1Router .Get ("/healtz" , handlerReadiness )
31
+ v1Router .Get ("/err" , handlerErr )
31
32
router .Mount ("/v1" , v1Router )
32
33
srv := & http.Server {
33
34
Handler : router ,
You can’t perform that action at this time.
0 commit comments