async-test-sanity.js 412 B

12345678910
  1. process.on('unhandledRejection', reason => {
  2. // If the reason is already an Error object, throw it directly to preserve the stack trace.
  3. if (reason instanceof Error) {
  4. throw reason;
  5. } else {
  6. // If the reason is not an Error (e.g., a string, number, or other primitive),
  7. // create a new Error object with the reason as its message.
  8. throw new Error(`Unhandled rejection: ${reason}`);
  9. }
  10. });