feat: add project-owned error catalogs and HTTP 200 failure contracts
This commit is contained in:
@@ -73,10 +73,10 @@ func AccessLog(options ...AccessLogOption) httpx.Middleware {
|
||||
return func(ctx *httpx.Context) error {
|
||||
started := time.Now()
|
||||
err := next(ctx)
|
||||
status := ctx.Status()
|
||||
if err != nil && !ctx.Responded() {
|
||||
status = apierrors.From(err).Status
|
||||
ctx.WriteError(err)
|
||||
}
|
||||
status := ctx.Status()
|
||||
duration := time.Since(started)
|
||||
slow := settings.slowThreshold > 0 && duration >= settings.slowThreshold
|
||||
attrs := []any{
|
||||
@@ -87,6 +87,16 @@ func AccessLog(options ...AccessLogOption) httpx.Middleware {
|
||||
"durationMs", duration.Seconds() * 1000,
|
||||
"clientIp", ctx.ClientIP(),
|
||||
}
|
||||
failure := ctx.Failure()
|
||||
if failure == nil && err != nil {
|
||||
failure = ctx.ResolveError(err)
|
||||
}
|
||||
if failure != nil {
|
||||
attrs = append(attrs, "failed", true, "errorKey", failure.Code)
|
||||
if failure.BusinessCode != nil {
|
||||
attrs = append(attrs, "businessCode", failure.BusinessCode)
|
||||
}
|
||||
}
|
||||
if slow {
|
||||
attrs = append(attrs, "slow", true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user