dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

When Throwing an Exception, shouldn't the lambda invocation fail? #123

Closed aterreno closed 4 years ago

aterreno commented 5 years ago

Hello, I am pretty sure I got this working in the past, so I am not sure if it's a new version of this library or express or if I am missing something ridiculously obvious but basically I was quite sure that if an endpoint in express throws an exception this would then fail the lambda invocation.

I'd really like to have this behaviour as I am using IOPipe and I'd like to monitor when something is not right.

I've put together my code here on a gist: https://gist.github.com/aterreno/a6f26acb31206cdfd3bdb6bead9f5c97

TLTR;

app.get("/throw", function(_req, _res, next) {
  console.log("About to throw");
  return next(new Error("Throw this"));
});

app.use(function(err, _req, res, _next) {
  console.error(err.stack);
  res.status(500).send(`Something broke: ${err.message}`);
});

Thanks for your help!

dougmoscrop commented 4 years ago

No, as far as I can remember, that has never caused the invocation to fail unless it bubbled up as an unhanded exception all the way in to generic Node (like onError type stuff)

In general I try to keep invocation failures to a minimum as a sign something has gone very wrong, and instead use logging and custom alarm metrics to detect HTTP status codes.

aterreno commented 4 years ago

thanks @dougmoscrop for looking into this, almost a year passed and I ended up doing just as you said.