-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Unsupported Media Type Error #2899
Comments
Are you open for a PR? |
Nowadays, you can't check it in the |
Yes it is possible to check in the errorHandler but I think that is not that clean. And you do not have the possibility to define different error shapes in different plugins. |
Instead of focusing on making this customizable, we should focus on allowing the error handler to call the one of the plugin above it. In this way we could even have route-specific error handlers. |
After looking into the code again, I realized that I made a mistake. it is NOT possible to catch the error in the |
|
@mcollina Doesn't it work like that right now already? I tried to write a test for it, that passes, but maybe I'm missing something. test('custom root and custom plugin error handling with nested plugin throwing', t => {
t.plan(3)
const fastify = Fastify()
fastify.register((instance, options, done) => {
instance.setErrorHandler((err, req, reply) => {
throw new Error('/a error')
})
instance.register((subinstance, options, done) => {
subinstance.get('/c', function (req, reply) {
throw new Error('/a/b/c error')
})
done()
}, { prefix: '/b' })
done()
}, { prefix: '/a' })
fastify.setErrorHandler((err, req, reply) => {
throw new Error('/ error')
})
fastify.inject({
url: '/a/b/c',
method: 'GET'
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 500)
const payload = JSON.parse(res.payload)
t.same(payload.message,'/a error')
})
}) |
Done in #3261 It will be released in fastify v4 |
馃殌 Feature Proposal
Currently, if no matching content type parser is available, a predefined
Unsupported Media Type
error is thrown. There should be the possibility that the user can define this error object himself.Motivation
This would have 2 advantages:
Example
This could be implemented like the
addContentTypeParser
API.or like this, which would give the user even more possibilities:
The text was updated successfully, but these errors were encountered: