Last active
May 15, 2021 22:05
-
-
Save SarasArya/8626a311186a39572421b3eb6a9434ba to your computer and use it in GitHub Desktop.
Serverless Sentry Error Handler example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node version 10.x AWS Lambda Serverless framework | |
const Sentry = require('@sentry/node'); // sentry version "@sentry/node": "^5.5.0", | |
Sentry.init({ | |
dsn: 'https://[email protected]/1234567', | |
async beforeSend(event) { | |
console.log('\n Caught an exception \n'); | |
return event; | |
}, | |
}); | |
module.exports.v1createBill = async (event, context) => { | |
try { | |
console.log(sss); // this will throw a Reference Error | |
}catch(err){ | |
Sentry.configureScope(scope => scope.setExtra('whatever', event.context.body)); | |
Sentry.captureException(err); | |
await Sentry.flush(2500); | |
console.log('Submitted the error'); | |
return { | |
statusCode: err.statusCode || 500, | |
headers: { | |
'Access-Control-Allow-Origin': '*', // Required for CORS support to work | |
}, | |
body: JSON.stringify({ message: err.message }), | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment