Skip to content

Commit f7b2e9f

Browse files
committed
Do not wrap decode errors that are already service errors
This makes it possible for the decoding code to return proper HTTP statuses depending on the name of error. As of this PR, this is only used to return 415 "Unsupported Media Type" when an unsupported content type is used to encode the request payload.
1 parent f2a07d6 commit f7b2e9f

File tree

3 files changed

+197
-1
lines changed

3 files changed

+197
-1
lines changed

http/codegen/templates/request_decoder.go.tpl

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ func {{ .RequestDecoder }}(mux goahttp.Muxer, decoder func(*http.Request) goahtt
44
{{- if .MultipartRequestDecoder }}
55
var payload {{ .Payload.Ref }}
66
if err := decoder(r).Decode(&payload); err != nil {
7+
var gerr *goa.ServiceError
8+
if errors.As(err, &gerr) {
9+
return nil, gerr
10+
}
711
return nil, goa.DecodePayloadError(err.Error())
812
}
913
{{- else if .Payload.Request.ServerBody }}
@@ -22,6 +26,10 @@ func {{ .RequestDecoder }}(mux goahttp.Muxer, decoder func(*http.Request) goahtt
2226
err = nil
2327
} else {
2428
{{- end }}
29+
var gerr *goa.ServiceError
30+
if errors.As(err, &gerr) {
31+
return nil, gerr
32+
}
2533
return nil, goa.DecodePayloadError(err.Error())
2634
{{- if not .Payload.Request.MustHaveBody }}
2735
}

0 commit comments

Comments
 (0)