Skip to content

Commit 5ea6e8e

Browse files
committed
fix: use raw url string in huma err logger
chore: wrap errors in SetResponse for logging
1 parent 82617a9 commit 5ea6e8e

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

api/internal/httperr/huma.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ func ServerErrorOrNotFound(err error) *InternalHTTPError {
195195

196196
func (s *Service) logHumaReqErr(hctx huma.Context, status int, msg string, errs any) {
197197
ctx := hctx.Context()
198-
uri, err := util.RedactQueryParam(hctx.URL().Path, "key")
198+
rawURL := hctx.URL()
199+
uri, err := util.RedactQueryParam(rawURL.String(), "key")
199200
if err != nil {
200201
s.cfg.logger.ErrorContext(ctx, "query parameter redactor failed", "error", err)
201202
}

api/internal/middleware/audit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (m *apiMw) AttachClaims(ctx huma.Context, next func(huma.Context)) {
8686

8787
claims, err := mapClaims(userJWT)
8888
if err != nil {
89-
m.httperr.SetResponse(ctx, httperr.Forbidden(err))
89+
m.httperr.SetResponse(ctx, httperr.Forbidden(fmt.Errorf("mapClaims(userJWT); %w", err)))
9090
return
9191
}
9292

@@ -119,7 +119,7 @@ func (m *apiMw) AttachProfile(ctx huma.Context, next func(huma.Context)) {
119119
if success, _ := reqCtx.Value(ctxkey.AppKeyAuthSuccess).(bool); success {
120120
p, err := m.DBService.ProfileGetForEDIPI(reqCtx, 79)
121121
if err != nil {
122-
m.httperr.SetResponse(ctx, httperr.Forbidden(err))
122+
m.httperr.SetResponse(ctx, httperr.Forbidden(fmt.Errorf("m.DBService.ProfileGetForEDIPI(reqCtx, 79) query error (app user); %w", err)))
123123
return
124124
}
125125
newCtx := context.WithValue(reqCtx, ctxkey.Profile, p)
@@ -137,7 +137,7 @@ func (m *apiMw) AttachProfile(ctx huma.Context, next func(huma.Context)) {
137137
}
138138
p, err := m.DBService.ProfileGetForToken(reqCtx, keyID)
139139
if err != nil {
140-
m.httperr.SetResponse(ctx, httperr.Forbidden(err))
140+
m.httperr.SetResponse(ctx, httperr.Forbidden(fmt.Errorf("m.DBService.ProfileGetForToken(reqCtx, keyID); %w", err)))
141141
return
142142
}
143143
newCtx := context.WithValue(reqCtx, ctxkey.Profile, p)
@@ -154,7 +154,7 @@ func (m *apiMw) AttachProfile(ctx huma.Context, next func(huma.Context)) {
154154

155155
p, err := m.DBService.ProfileGetWithTokensForClaims(reqCtx, claims)
156156
if err != nil {
157-
m.httperr.SetResponse(ctx, httperr.Forbidden(err))
157+
m.httperr.SetResponse(ctx, httperr.Forbidden(fmt.Errorf("m.DBService.ProfileGetWithTokensForClaims query error; %w", err)))
158158
return
159159
}
160160

api/internal/middleware/jwt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (m *apiMw) JWT(ctx huma.Context, next func(huma.Context)) {
3030
case m.Config.AuthJWTMocked:
3131
userJWT, err = mockJWT(ctx)
3232
if err != nil {
33-
m.httperr.SetResponse(ctx, httperr.Forbidden(err))
33+
m.httperr.SetResponse(ctx, httperr.Forbidden(fmt.Errorf("mockJWT(ctx); %w", err)))
3434
return
3535
}
3636
default:

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
6666
github.com/XSAM/otelsql v0.39.0/go.mod h1:uMOXLUX+wkuAuP0AR3B45NXX7E9lJS2mERa8gqdU8R0=
6767
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
6868
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
69+
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
6970
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.19.5/go.mod h1:VNM08cHlOsIbSHRqb6D/M2L4kKXfJv3A2/f0GNbOQSc=
7071
github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.7.87/go.mod h1:ZeQC4gVarhdcWeM1c90DyBLaBCNhEeAbKUXwVI/byvw=
7172
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.44.0/go.mod h1:mWB0GE1bqcVSvpW7OtFA0sKuHk52+IqtnsYU2jUfYAs=
@@ -146,6 +147,7 @@ github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
146147
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
147148
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc=
148149
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
150+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
149151
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak=
150152
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
151153
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=

0 commit comments

Comments
 (0)