diff --git a/internal/credit/httpdriver/grant.go b/internal/credit/httpdriver/grant.go index 9db4cfe17..fba13f364 100644 --- a/internal/credit/httpdriver/grant.go +++ b/internal/credit/httpdriver/grant.go @@ -89,7 +89,7 @@ func (h *grantHandler) ListGrants() ListGrantsHandler { commonhttp.JSONResponseEncoder[[]api.EntitlementGrant], httptransport.AppendOptions( h.options, - httptransport.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter) bool { + httptransport.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter, _ *http.Request) bool { if _, ok := err.(*models.GenericUserError); ok { commonhttp.NewHTTPError( http.StatusBadRequest, @@ -138,7 +138,7 @@ func (h *grantHandler) VoidGrant() VoidGrantHandler { commonhttp.EmptyResponseEncoder[interface{}](http.StatusNoContent), httptransport.AppendOptions( h.options, - httptransport.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter) bool { + httptransport.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter, _ *http.Request) bool { if _, ok := err.(*models.GenericUserError); ok { commonhttp.NewHTTPError( http.StatusBadRequest, diff --git a/internal/entitlement/httpdriver/errors.go b/internal/entitlement/httpdriver/errors.go index ca84c134f..3dd895763 100644 --- a/internal/entitlement/httpdriver/errors.go +++ b/internal/entitlement/httpdriver/errors.go @@ -12,7 +12,7 @@ import ( ) func getErrorEncoder() httptransport.ErrorEncoder { - return func(ctx context.Context, err error, w http.ResponseWriter) bool { + return func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool { // user errors return commonhttp.HandleErrorIfTypeMatches[*productcatalog.FeatureNotFoundError](ctx, http.StatusNotFound, err, w) || commonhttp.HandleErrorIfTypeMatches[*entitlement.NotFoundError](ctx, http.StatusNotFound, err, w) || diff --git a/internal/ingest/ingestdriver/http_transport.go b/internal/ingest/ingestdriver/http_transport.go index 60e8c7cd9..62b1f7fb2 100644 --- a/internal/ingest/ingestdriver/http_transport.go +++ b/internal/ingest/ingestdriver/http_transport.go @@ -127,7 +127,7 @@ type ingestEventsErrorEncoder struct { CommonErrorEncoder httptransport.ErrorEncoder } -func (e ingestEventsErrorEncoder) encode(ctx context.Context, err error, w http.ResponseWriter) bool { +func (e ingestEventsErrorEncoder) encode(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool { if e := (ErrorInvalidContentType{}); errors.As(err, &e) { models.NewStatusProblem(ctx, e, http.StatusBadRequest).Respond(w) @@ -141,7 +141,7 @@ func (e ingestEventsErrorEncoder) encode(ctx context.Context, err error, w http. } if e.CommonErrorEncoder != nil { - return e.CommonErrorEncoder(ctx, err, w) + return e.CommonErrorEncoder(ctx, err, w, r) } models.NewStatusProblem(ctx, errors.New("something went wrong"), http.StatusInternalServerError).Respond(w) diff --git a/internal/productcatalog/httpdriver/errors.go b/internal/productcatalog/httpdriver/errors.go index c65a43d29..76b48bf50 100644 --- a/internal/productcatalog/httpdriver/errors.go +++ b/internal/productcatalog/httpdriver/errors.go @@ -11,7 +11,7 @@ import ( ) func getErrorEncoder() httptransport.ErrorEncoder { - return func(ctx context.Context, err error, w http.ResponseWriter) bool { + return func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool { return commonhttp.HandleErrorIfTypeMatches[*productcatalog.FeatureNotFoundError](ctx, http.StatusNotFound, err, w) || commonhttp.HandleErrorIfTypeMatches[*productcatalog.FeatureInvalidFiltersError](ctx, http.StatusBadRequest, err, w) || commonhttp.HandleErrorIfTypeMatches[*productcatalog.FeatureInvalidMeterAggregationError](ctx, http.StatusBadRequest, err, w) || diff --git a/pkg/framework/transport/httptransport/handler.go b/pkg/framework/transport/httptransport/handler.go index 566c35047..32075d165 100644 --- a/pkg/framework/transport/httptransport/handler.go +++ b/pkg/framework/transport/httptransport/handler.go @@ -64,7 +64,7 @@ type ResponseEncoder[Response any] func(ctx context.Context, w http.ResponseWrit // Users are encouraged to use custom ErrorEncoders to encode HTTP errors to // their clients, and will likely want to pass and check for their own error // types. See the example shipping/handling service. -type ErrorEncoder func(ctx context.Context, err error, w http.ResponseWriter) bool +type ErrorEncoder func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool // ErrorHandler receives a transport error to be processed for diagnostic purposes. // Usually this means logging the error. @@ -85,7 +85,7 @@ func (h handler[Request, Response]) ServeHTTP(w http.ResponseWriter, r *http.Req // Might be a client error (can be encoded, non-terminal) // Might be a server error (terminal) - handled := h.encodeError(ctx, err, w) + handled := h.encodeError(ctx, err, w, r) if !handled { h.errorHandler.HandleContext(ctx, err) } @@ -98,7 +98,7 @@ func (h handler[Request, Response]) ServeHTTP(w http.ResponseWriter, r *http.Req // Might be a client error (can be encoded, non-terminal) // Might be a server error (terminal) - handled := h.encodeError(ctx, err, w) + handled := h.encodeError(ctx, err, w, r) if !handled { h.errorHandler.HandleContext(ctx, err) } @@ -114,9 +114,9 @@ func (h handler[Request, Response]) ServeHTTP(w http.ResponseWriter, r *http.Req } } -func (h handler[Request, Response]) encodeError(ctx context.Context, err error, w http.ResponseWriter) bool { +func (h handler[Request, Response]) encodeError(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool { for _, errorEncoder := range h.errorEncoders { - if errorEncoder(ctx, err, w) { + if errorEncoder(ctx, err, w, r) { return true } }