Form
extractor should return 422 Unprocessable Entity for deserialization errors
#1680
Closed
1 task done
Labels
A-axum
C-enhancement
Category: A PR with an enhancement
E-easy
Call for participation: Experience needed to fix: Easy / not much
E-help-wanted
Call for participation: Help is requested to fix this issue.
Feature Request
Motivation
I noticed this when upgrading a project from axum 0.5 to 0.6, which led to some failing tests of invalid form data: deserialization errors from the
Form
extractor now convert into400 Bad Request
responses, when previously they were422 Unprocessable Entity
responses. Per the semantics discussed in #1378 it seems like422 Unprocessable Entity
would be the more appropriate response for syntactically valid form data that could not be deserialized.Proposal
From doing some digging around, it looks like this change occurred to fix #1378. At that time, the rejection for a
Form
deserialization error was alsoFailedToDeserializeQueryString
:axum/axum/src/extract/rejection.rs
Lines 141 to 151 in 74105fc
Later, in #1496,
Form
gets a dedicatedFailedToDeserializeForm
variant:axum/axum/src/extract/rejection.rs
Lines 99 to 109 in 351df64
However, this rejection is still set to return a
400 Bad Request
:axum/axum/src/extract/rejection.rs
Lines 73 to 79 in 211de92
Since the
Form
andQuery
extractors now have dedicated rejection types, it seems we could simply update thestatus
forFailedToDeserializeForm
toUNPROCESSABLE_ENTITY
without disturbing the original fix in #1378. I'd be happy to make that PR if it's desirable and I'm not missing anything. This would be a breaking change (assuming the rejection statuses are covered by the versioning policy, and this isn't considered a bug).The text was updated successfully, but these errors were encountered: