Closed robahtou closed 1 year ago
Hello, and thank you for your question. The type
is just a filter, so when it doesn't match, the parser will just not parse the request body. It does not error or anything. This is what the readme says about the expected behavior:
All middlewares will populate the req.body property with the parsed body when the Content-Type request header matches the type option, or an empty object ({}) if [...] the Content-Type was not matched [...].
I hope that helps! If you want to outright reject requests without a specific content-type, you'll want to add code for that in your handler 👍
For example, I explicitly set the
type
in the JSONbody-parser
:Then I hit the API with curl:
I expected an error to be thrown since the
content-type
does not match the JSONbody-parser
. But this isn't the case. The docs are not very clear on what to expect withtype
. Can someone help explain what to expect with settingtype
and when a request doesn't match thecontent-type
?Ideally I want to capture this with express error handler (if this is an error) or just be able to handle in express when there is a content-type mismatch.