(error: Error, extras?: { [key: string]: any })
| 22 | } |
| 23 | |
| 24 | export function errorHandler(error: Error, extras?: { [key: string]: any }) { |
| 25 | console.error(error); |
| 26 | |
| 27 | if (!process.env.SENTRY_DSN) { |
| 28 | console.log( |
| 29 | 'Skipping Sentry error reporting because SENTRY_DSN is not set' |
| 30 | ); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | initSentry(); |
| 35 | |
| 36 | try { |
| 37 | withScope(scope => { |
| 38 | scope.setTag('service', serviceName); |
| 39 | scope.setTag('function_name', assertEnv('AWS_LAMBDA_FUNCTION_NAME')); |
| 40 | |
| 41 | for (const [k, v] of Object.entries(extras)) { |
| 42 | scope.setExtra(k, v); |
| 43 | } |
| 44 | |
| 45 | captureException(error); |
| 46 | }); |
| 47 | } catch (e) { |
| 48 | console.error(`Failed to report error to Sentry: ${e}`); |
| 49 | } |
| 50 | } |
no test coverage detected