Skip to content

Commit

Permalink
Add server-side error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
CHTJonas committed Feb 14, 2021
1 parent 5bf7d94 commit 2ef4dfc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func newController(driver *SQLDriver, token string, addr string) *Controller {
}

func (c *Controller) ListenAndServe() error {
c.router.Use(recoveryMiddleware)
c.router.Use(logMiddleware)
c.router.Use(headerMiddleware)
c.router.Use(c.authMiddleware)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func recoveryMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
http.Error(w, "500 Internal Server Error", http.StatusInternalServerError)
http.Error(w, "500 internal server error", http.StatusInternalServerError)
log.Println("An internal server error occurred:", err)
log.Println(string(debug.Stack()))
}
Expand Down

0 comments on commit 2ef4dfc

Please sign in to comment.