-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
errorhandling.ts
40 lines (35 loc) · 1.09 KB
/
errorhandling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { getClient } from '@sentry/core';
import { consoleSandbox, logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../debug-build';
import type { NodeClient } from '../sdk/client';
const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
/**
* @hidden
*/
export function logAndExitProcess(error: Error): void {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(error);
});
const client = getClient<NodeClient>();
if (client === undefined) {
DEBUG_BUILD && logger.warn('No NodeClient was defined, we are exiting the process now.');
global.process.exit(1);
return;
}
const options = client.getOptions();
const timeout =
(options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) ||
DEFAULT_SHUTDOWN_TIMEOUT;
client.close(timeout).then(
(result: boolean) => {
if (!result) {
DEBUG_BUILD && logger.warn('We reached the timeout for emptying the request buffer, still exiting now!');
}
global.process.exit(1);
},
error => {
DEBUG_BUILD && logger.error(error);
},
);
}