-
I'm using Sentry lambda layer. When having unhandled errors catch here, it would be nice to be able to custom the response returned. Today, the error is re-throw, which leads to have 502 error. Instead I would prefer to have a 500 in that case. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 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 using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});
const handler = async (event, context) => {
// Your handler code
};
exports.handler = (...args) => {
try {
Sentry.AWSLambda.wrapHandler(handler)(...args);
} catch (e) {
return { statusCode: 500 };
}
}; |
Beta Was this translation helpful? Give feedback.
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 callcaptureException
. Obviously, if that last wrapper throws an error it won't be reported to Sentry.Kinda like this (not actual code):