Skip to content

Commit

Permalink
πŸ”„ Sync from monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mojo-machine[bot] committed Dec 1, 2023
1 parent 4e59732 commit 3f9ee6f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/middleware/request/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"time"

"github.com/sirupsen/logrus"
"github.com/wearemojo/mojo-public-go/lib/cher"
"github.com/wearemojo/mojo-public-go/lib/clog"
"github.com/wearemojo/mojo-public-go/lib/gerrors"
"github.com/wearemojo/mojo-public-go/lib/merr"
"github.com/wearemojo/mojo-public-go/lib/mlog"
"github.com/wearemojo/mojo-public-go/lib/slicefn"
)

type responseWriter struct {
Expand Down Expand Up @@ -112,7 +115,13 @@ func Logger(log *logrus.Entry) func(http.Handler) http.Handler {
fn = mlog.Info
}

fn(ctx, merr.New(ctx, "request_failed", nil, err))
if mErr, ok := gerrors.As[merr.E](err); ok {
fn(ctx, mErr)
} else if cErr, ok := gerrors.As[cher.E](err); ok {
fn(ctx, merr.New(ctx, merr.Code(cErr.Code), merr.M(cErr.Meta), slicefn.Map(cErr.Reasons, func(r cher.E) error { return r })...))
} else {
fn(ctx, merr.New(ctx, "unexpected_request_failure", nil, err))
}
}
})
}
Expand Down

0 comments on commit 3f9ee6f

Please sign in to comment.