question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trowing error in async/await route times out when using async handler

See original GitHub issue

So I’m not sure I am doing everything correctly here. But how come throwing an Error in this case causes the lambda to timeout?

How can I prevent the lambda from timing out?

import express from 'express';
import awsServerlessExpress from 'aws-serverless-express';

const app = express();
app.get('/throwerror', async (req, res) => {
    throw new Error('This is an error');
});

const server = awsServerlessExpress.createServer(app);
export const handler = async (event: any, context: any) => awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
andidevcommented, Sep 11, 2018

Removing async is not an option since I have asyncronious calls to the database. Using https://github.com/Abazhenov/express-async-handler workes though.

The reson why I created this bug was because I thought it was a bit extreme for the lambda to time out on a async error. But I guess it is not up to aws-serverless-express to take care of that.

1reaction
brettstackcommented, Sep 7, 2018

Thanks for the comment. This sounds like a bug. I’ll fix and release as soon as I can

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trowing error in async/await route times out when using ...
So I'm not sure I am doing everything correctly here. But how come throwing an Error in this case causes the lambda to...
Read more >
express.js async router and error handling
I use following approach: Create asyncWrap as helper middleware: const asyncWrap = fn => function asyncUtilWrap (req, res, next, ...
Read more >
Async Error Handling in Node.js + Express | by Nate Jones
If synchronous code throws an error, then Express will catch and process it." But, for async: "For errors returned from asynchronous functions ...
Read more >
Error handling with Async/Await in JS | by Ian Segers
This works as expected, we call the function thisThrows() which throws a regular error, we catch it, log the error and optionally we...
Read more >
Using async/await in Express
The easiest way to use async/await in Express is use express-async-handler. This article shows you why, and how you can use it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found