Skip request handler and directly pass error to first error handler
See original GitHub issueI have this piece of code
const express = require('express')
const app = express()
const { buildCheckFunction, validationResult } = require('express-validator/check');
const checkQuery = buildCheckFunction(['query']);
app.get('/', [ checkQuery('id').isUUID() ], (req, res) => {
const errors = validationResult(req);
console.log(errors.array());
res.send('')
})
app.listen(3000, () => console.log('Example app listening on port 3000!'))
Right now I always get inside my handler and have to manually check for errors, I want to directly pass the execution to my first error handler and have display the error there, without entering my request callback.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Error handling - Express.js
If you pass anything to the next() function (except the string 'route' ), Express regards the current request as being an error and...
Read more >A Guide to Error Handling in Express.js | Scout APM Blog
Basic Quick Tutorial: Setting up Error Handling in Express.js · Step 1: Create and Setup Project · Step 2: Setup the Server ·...
Read more >Error handling - Apollo GraphQL Docs
A client sent the hash of a query string to execute via automatic persisted queries, but the server has disabled APQ. OPERATION_RESOLUTION_FAILURE. The...
Read more >Error Handling in Express - Reflectoring
When an error occurs, we call the next(error) function and pass the error object as input. The Express framework will process this by...
Read more >RxJs Error Handling: Complete Practical Guide
Handling errors using the subscribe call is sometimes all that we need, but this error handling approach is limited. Using this approach, we ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a workaround, you can create function to take your validators as params and add a handler at the end to trigger the error handler.
@fedeci a wrapper for something like this could be pretty simple, wdyt?