Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

timeout.js 1019 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  1. const timeout = require('express-timeout-handler')
  2. // Heroku router requests timeout after 30 seconds. We should stop them earlier!
  3. const maxRequestTimeout = parseInt(process.env.REQUEST_TIMEOUT, 10) || 10000
  4. module.exports = timeout.handler({
  5. // Default timeout for all endpoints
  6. // To override for a given router/endpoint, use `require('express-timeout-handler').set(...)`
  7. timeout: maxRequestTimeout,
  8. // IMPORTANT:
  9. // We cannot allow the middleware to disable the `res` object's methods like
  10. // it does by default if we want to use `next` in the `onTimeout` handler!
  11. disable: [],
  12. onTimeout: function (req, res, next) {
  13. // Create a custom timeout error
  14. const timeoutError = new Error('Request timed out')
  15. timeoutError.statusCode = 503
  16. timeoutError.code = 'ETIMEDOUT'
  17. // Pass the error to our Express error handler for consolidated processing
  18. return next(timeoutError)
  19. }
  20. // Can also set an `onDelayedResponse` property IF AND ONLY IF you allow for disabling methods
  21. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...