Skip to content

Commit

Permalink
add stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Nov 16, 2023
1 parent 3e30fe1 commit a28b722
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"os/signal"
"runtime/debug"
"strings"
"syscall"

Expand Down Expand Up @@ -157,7 +158,7 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, database db.S
return app
}

// Code below copied from device-data-api/main.go
// ErrorHandler handles errors returned from fiber handlers / controllers
func ErrorHandler(c *fiber.Ctx, err error, logger zerolog.Logger) error {
// Default error info
code := fiber.StatusInternalServerError
Expand All @@ -173,7 +174,8 @@ func ErrorHandler(c *fiber.Ctx, err error, logger zerolog.Logger) error {
message = e.Message
}

logger.Err(err).Int("code", code).Str("path", strings.TrimPrefix(c.Path(), "/")).Msg("Failed request.")
logger.Err(err).Int("code", code).Str("path", strings.TrimPrefix(c.Path(), "/")).
Str("stack", string(debug.Stack())).Msg("Failed request.")

return c.Status(code).JSON(CodeResp{Code: code, Message: message})
}
Expand Down

0 comments on commit a28b722

Please sign in to comment.