Skip to content

Commit

Permalink
debug mode should add more detailed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
udsamani committed Sep 11, 2024
1 parent 7ec8f2c commit 65ffc35
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/publicapi/middleware/error_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"net/http"
"os"

"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
Expand Down Expand Up @@ -35,14 +36,17 @@ func CustomHTTPErrorHandler(err error, c echo.Context) {
// and map it to APIError and send in appropriate message.= http.StatusInternalServerError
message = "internal server error"
code = c.Response().Status

if isDebugMode() {
message = err.Error()
}
}

requestID := c.Request().Header.Get(echo.HeaderXRequestID)

// Don't override the status code if it is already been set.
// This is something that is advised by ECHO framework.
if !c.Response().Committed {

if c.Request().Method == http.MethodHead {
err = c.NoContent(code)
} else {
Expand All @@ -58,3 +62,7 @@ func CustomHTTPErrorHandler(err error, c echo.Context) {
}

}

func isDebugMode() bool {
return os.Getenv("BACALHAU_DEBUG") == "true"
}

0 comments on commit 65ffc35

Please sign in to comment.