From c1cf4c72dfef7d8eadc3ca4cd18fd5c79d015734 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Fri, 25 Nov 2022 17:01:57 +0800 Subject: [PATCH] Sort out previous message logic --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 86ac857..220ccb6 100644 --- a/index.js +++ b/index.js @@ -83,12 +83,12 @@ export default function pTimeout(promise, options) { if (message === false) { resolve(); + } else if (message instanceof Error) { + reject(message); + } else { + const errorMessage = message ?? `Promise timed out after ${milliseconds} milliseconds`; + reject(new TimeoutError(errorMessage)); } - - const errorMessage = typeof message === 'string' ? message : `Promise timed out after ${milliseconds} milliseconds`; - const timeoutError = message instanceof Error ? message : new TimeoutError(errorMessage); - - reject(timeoutError); }, milliseconds); (async () => {