File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ export default function pTimeout(promise, options) {
66
66
} ) ;
67
67
}
68
68
69
+ // We create the error outside of `setTimeout` to preserve the stack trace.
70
+ const timeoutError = new TimeoutError ( ) ;
71
+
69
72
timer = customTimers . setTimeout . call ( undefined , ( ) => {
70
73
if ( fallback ) {
71
74
try {
@@ -86,8 +89,8 @@ export default function pTimeout(promise, options) {
86
89
} else if ( message instanceof Error ) {
87
90
reject ( message ) ;
88
91
} else {
89
- const errorMessage = message ?? `Promise timed out after ${ milliseconds } milliseconds` ;
90
- reject ( new TimeoutError ( errorMessage ) ) ;
92
+ timeoutError . message = message ?? `Promise timed out after ${ milliseconds } milliseconds` ;
93
+ reject ( timeoutError ) ;
91
94
}
92
95
} , milliseconds ) ;
93
96
You can’t perform that action at this time.
0 commit comments