Files
vercel/api/_lib/util/error-handler.ts
Ethan Arrowood 9c768b98b7 [tests] Migrate from yarn to pnpm (#9198)
<picture data-single-emoji=":pnpm:" title=":pnpm:"><img class="emoji" src="https://single-emoji.vercel.app/api/emoji/eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..4mJzrO94AnSn0Pue.4apgaKtTUdQ-wxNyahjdJj28u8bbXreLoTA8AGqYjLta3MrsFvbo9DsQFth4CoIkBgXFhQ5_BVcKNfYbwLg4bKzyIvItKe4OFS8AzG7Kkicz2kUUZk0.nXyK_PvHzZFGA-MQB6XHfA" alt=":pnpm:" width="20" height="auto" align="absmiddle"></picture> 

yarn has become increasingly more difficult to use as the v1 we rely on no longer receives updates. pnpm is faster and is actively maintained. 

This PR migrates us to pnpm.
2023-01-11 23:35:13 +00:00

46 lines
1.0 KiB
TypeScript

import { init, captureException, withScope } from '@sentry/node';
import { assertEnv } from './assert-env';
const serviceName = 'api-frameworks';
let sentryInitDone = false;
function initSentry() {
if (sentryInitDone) {
return;
}
sentryInitDone = true;
init({
// Cannot figure out whats going wrong here. VSCode resolves this fine. But when we build it blows up.
// @ts-ignore
dsn: assertEnv('SENTRY_DSN'),
environment: process.env.NODE_ENV || 'production',
release: `${serviceName}`,
});
}
export function errorHandler(error: Error, extras?: { [key: string]: any }) {
if (!process.env.SENTRY_DSN) {
return;
}
initSentry();
try {
withScope(scope => {
scope.setTag('service', serviceName);
scope.setTag('function_name', assertEnv('AWS_LAMBDA_FUNCTION_NAME'));
for (const [k, v] of Object.entries(extras)) {
scope.setExtra(k, v);
}
captureException(error);
});
} catch (e) {
console.error(`Failed to report error to Sentry: ${e}`);
}
}