errorhandling.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { getClient } from '@sentry/core';
  2. import { consoleSandbox, logger } from '@sentry/utils';
  3. import { DEBUG_BUILD } from '../../debug-build.js';
  4. const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
  5. /**
  6. * @hidden
  7. */
  8. function logAndExitProcess(error) {
  9. consoleSandbox(() => {
  10. // eslint-disable-next-line no-console
  11. console.error(error);
  12. });
  13. const client = getClient();
  14. if (client === undefined) {
  15. DEBUG_BUILD && logger.warn('No NodeClient was defined, we are exiting the process now.');
  16. global.process.exit(1);
  17. }
  18. const options = client.getOptions();
  19. const timeout =
  20. (options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) ||
  21. DEFAULT_SHUTDOWN_TIMEOUT;
  22. client.close(timeout).then(
  23. (result) => {
  24. if (!result) {
  25. DEBUG_BUILD && logger.warn('We reached the timeout for emptying the request buffer, still exiting now!');
  26. }
  27. global.process.exit(1);
  28. },
  29. error => {
  30. DEBUG_BUILD && logger.error(error);
  31. },
  32. );
  33. }
  34. export { logAndExitProcess };
  35. //# sourceMappingURL=errorhandling.js.map