Comments (2)
Check the README... https://github.com/expressjs/timeout#express-3x and the multiple examples.
from timeout.
Edit: having issues with my comment. Will update shortly...
@Omar1123 The problem is that connect-timeout will call next(err) if you do not pass {respond: false} in the options. This will cause the express router to skip all of your middleware(s) and to your error handler. - https://expressjs.com/en/guide/error-handling.html
To me, the documentation seems outdated (express v3) or incorrect because haltOnTimedout will never get called unless you pass {respond: false}, yet the example uses the default { respond: true } with haltOnTimedout as middleware.
Putting it together, you can either pass { respond: false } and create your own error to pass to your error handler as follows:
function haltOnTimedout(req, res, next){
if (!req.timedout){
next();
}
else{
let err = new Error("My custom timeout error");
err.status = 504;
next(err);
}
}
function errorHandler( function(err, req, res, next) {
//handle your timeout error here
res.sendStatus(err.status)
});
router.post( '/upload', connectTimeout('1s', { respond: false } ), multipartMiddleware, haltOnTimedout, successHandler, errorHandler)
Or you can use default {respond: true} which will skip your haltOnTimedout middleware and process the error from connect-timeout
router.post( '/upload', connectTimeout('1s'), multipartMiddleware, successHandler, timedoutErrorHandler)
from timeout.
Related Issues (20)
- Can't set headers after they are sent. HOT 1
- clearer documentation HOT 4
- 'connect-timeout' is possibly misleading HOT 2
- How to change timeout response? HOT 1
- How to catch "Can't set headers after they are sent." HOT 2
- Make this configurable via middleware.json HOT 1
- Extending the timeout HOT 7
- "Can't set headers after they are sent" error crashes the app HOT 1
- Documentation Update HOT 4
- Yarn certificate has expired. HOT 1
- What is the associate between this library and http's timeout HOT 1
- Should remove listener to timeout event HOT 7
- Turning off response timeouts HOT 2
- Make timeout action more flexible HOT 4
- Source code was not found HOT 4
- Override timeout for a route HOT 3
- req.timedout always come out to be false irrespective of timeout happens or not HOT 11
- `timedOut` instead of `timedout`?
- Upgrade Dependencies
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 timeout.