Comments (6)
Was it working in some cases before this? Or has it always been buggy?
from fastify.
A PR with a fix would really be nice.
from fastify.
Can replicate with:
const t = require('tap')
const test = t.test
const Fastify = require('.')
test('Fastify should throw on wrong options', async t => {
const app = Fastify()
app.addHook('onError', async (req, res, error) => {
t.pass('onError called')
})
app.setErrorHandler((error, req, res) => {
t.pass('errorHandler called')
if (error.message === 'unauthorized') {
return res.code(401).send('unauthorized')
}
throw error
})
app.get('/should_not_be_logged', {
onRequest: async () => {
throw new Error('unauthorized')
}
}, async (req, res) => {
res.send('OK')
})
app.get('/should_be_logged', {
onRequest: async () => {
throw new Error('unhandled error')
}
}, async (req, res) => {
res.send('OK')
})
await app.ready()
const res = await app.inject({
method: 'GET',
url: '/should_not_be_logged'
})
t.same(res.statusCode, 401)
const res2 = await app.inject({
method: 'GET',
url: '/should_be_logged'
})
t.same(res2.statusCode, 500)
t.end()
})
We should check.
In v3 I get:
# Subtest: Fastify should throw on wrong options
ok 1 - errorHandler called
ok 2 - should be equivalent
ok 3 - errorHandler called
ok 4 - onError called
ok 5 - should be equivalent
1..5
ok 1 - Fastify should throw on wrong options # time=55.848ms
In v4.10.0:
# Subtest: Fastify should throw on wrong options
ok 1 - onError called
ok 2 - errorHandler called
ok 3 - should be equivalent
ok 4 - onError called
ok 5 - errorHandler called
not ok 6 - unhandled error // memory error
It may me think if we have outdated docs, but for sure we must add a test to assert the order
from fastify.
Related Issues (20)
- `disableRequestLogging` should disable logs in default error handler HOT 6
- incorrect plugin identified for timeout HOT 1
- Backport webdav methods from next to current branch HOT 7
- OPTIONS HTTP method body processing HOT 3
- Dependency update for v5 HOT 1
- Merge main into next HOT 4
- Scoped FastifyRequest Customization via Generic Parameter in FastifyInstance HOT 1
- Flaky test on N|Solid 20 MacOS HOT 2
- Implement simple B-Tree for faster string comparisons HOT 5
- Throwing error in setErrorHandler after a JSON parse SyntaxError causes app to crash
- Where is the documentation for <Reply>.sendFile? HOT 2
- Switch to ajv/2020 for fastify 5 HOT 7
- Fastify v5 coordination HOT 6
- Does Validation-and-Serialization document's outdated?
- Should we drop Node.js v18 for v5? HOT 11
- `disableErrorLogging` option HOT 1
- Request hangs if you `await reply.status` in an async handler. HOT 15
- querystring with property of type number fails HOT 7
- Approval Request for Future State Proposal HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify.