mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-27 13:39:44 -08:00
8b19fdd5f0
* store n8n version string in a const and use that everywhere * reduce code duplication between Server and WebhookServer * unify redis checks * fix linting
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import config from '@/config';
|
|
import { ErrorReporterProxy } from 'n8n-workflow';
|
|
|
|
let initialized = false;
|
|
|
|
export const initErrorHandling = async () => {
|
|
if (initialized) return;
|
|
|
|
if (!config.getEnv('diagnostics.enabled')) {
|
|
initialized = true;
|
|
return;
|
|
}
|
|
|
|
// Collect longer stacktraces
|
|
Error.stackTraceLimit = 50;
|
|
|
|
const dsn = config.getEnv('diagnostics.config.sentry.dsn');
|
|
const { N8N_VERSION: release, ENVIRONMENT: environment } = process.env;
|
|
|
|
const { init, captureException } = await import('@sentry/node');
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
const { RewriteFrames } = await import('@sentry/integrations');
|
|
|
|
init({
|
|
dsn,
|
|
release,
|
|
environment,
|
|
integrations: (integrations) => {
|
|
integrations = integrations.filter(({ name }) => name !== 'OnUncaughtException');
|
|
integrations.push(new RewriteFrames({ root: process.cwd() }));
|
|
return integrations;
|
|
},
|
|
});
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
ErrorReporterProxy.error(error);
|
|
if (error.constructor?.name !== 'AxiosError') throw error;
|
|
});
|
|
|
|
ErrorReporterProxy.init({
|
|
report: (error, options) => captureException(error, options),
|
|
});
|
|
|
|
initialized = true;
|
|
};
|