Skip to content

Any way to return 500 status code instead of 502 when sentry lambda layer catches an error? #5858

Answered by lforst
srenault asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, generally we do not provide a way to return a different status code than 502 when a handler fails since we generally do not want to alter existing behavior.

I guess what you could do but is a bit more manual than applying the lambda layer, is using Sentry.AWSLambda.wrapHandler instead and wrapping the function once more, catching any errors and returning 500. Like that you at least don't have to manually call captureException. Obviously, if that last wrapper throws an error it won't be reported to Sentry.

Kinda like this (not actual code):

const Sentry = require("@sentry/serverless");

Sentry.AWSLambda.init({
  dsn: "DSN HERE",

  // We recommend adjusting this value in production, or…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by srenault
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants