Convert DecodingErrors thrown from request handling code to HTTP 400 …#161
Merged
czechboy0 merged 5 commits intoapple:mainfrom Nov 4, 2025
Merged
Conversation
czechboy0
requested changes
Oct 29, 2025
czechboy0
reviewed
Oct 29, 2025
czechboy0
reviewed
Oct 29, 2025
colindignazio
commented
Oct 29, 2025
czechboy0
approved these changes
Nov 3, 2025
Contributor
czechboy0
left a comment
There was a problem hiding this comment.
Looks great, thank you - I'll let @simonjbeaumont give this one more skim as well before merging.
simonjbeaumont
approved these changes
Nov 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The library does not gracefully handle when clients send requests with malformed request bodies, parameters, etc. If a client sends a request that for example is missing a required field or has a field that cannot be converted to the correct type, the server should respond with a
400indicating to the client that they have done something wrong. Instead, the library throws aDecodingErrorwhich propagates all the way up resulting in a500response which incorrectly tells the client that something went wrong on the server.Modifications
DecodingErrorsintoRuntimeErrors.ServerErrorconform toHTTPResponseConvertibleErrorHandlingMiddlewareto first check if the underlying error conforms toHTTPResponseConvertibleand if not use the values fromServerError. This allows theHTTPResponseConvertiblevalues set in aRuntimeErrorto be honoured after theRuntimeErroris transformed into aServerError.Result
Since
RuntimeErrorconforms toHTTPResponseConvertiblethese errors will get converted to400responses by theErrorHandlingMiddleware. This isn't a perfect solution because consumers of the library have to opt-in to theErrorHandlingMiddlewareto avoid returning500.Test Plan
400responses.