Skip to content

Commit

Permalink
feat: support oops error in WriteError
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 24, 2024
1 parent 8942074 commit 6cf64db
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/flanksource/commons/logger"
"github.com/labstack/echo/v4"
"github.com/samber/oops"
)

type HTTPError struct {
Expand Down Expand Up @@ -42,7 +43,14 @@ func WriteSuccess(c echo.Context, payload any) error {
}

func WriteError(c echo.Context, err error) error {
code, message, data := ErrorCode(err), ErrorMessage(err), ErrorData(err)
var code, message, data string
var oopsErr oops.OopsError
if errors.As(err, &oopsErr) {
code = oopsErr.Code()
message = oopsErr.Error()
} else {
code, message, data = ErrorCode(err), ErrorMessage(err), ErrorData(err)
}

if debugInfo := ErrorDebugInfo(err); debugInfo != "" {
logger.WithValues("code", code, "error", message).Errorf(debugInfo)
Expand Down

0 comments on commit 6cf64db

Please sign in to comment.