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 authored and moshloop committed Sep 24, 2024
1 parent c39007a commit 0168da3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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,6 +43,11 @@ func WriteSuccess(c echo.Context, payload any) error {
}

func WriteError(c echo.Context, err error) error {
var oopsErr oops.OopsError
if errors.As(err, &oopsErr) {
return c.JSON(ErrorStatusCode(oopsErr.Code()), oopsErr)
}

code, message, data := ErrorCode(err), ErrorMessage(err), ErrorData(err)

if debugInfo := ErrorDebugInfo(err); debugInfo != "" {
Expand Down

0 comments on commit 0168da3

Please sign in to comment.