From f257d79db660fcaa6597c724eb67e15bb03d1d98 Mon Sep 17 00:00:00 2001 From: eddienubes Date: Sat, 24 Aug 2024 16:38:45 +0200 Subject: [PATCH] fix: throw should reject in thenables --- src/Sage.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Sage.ts b/src/Sage.ts index b69c787..cffc15f 100644 --- a/src/Sage.ts +++ b/src/Sage.ts @@ -1,4 +1,4 @@ -import { HttpMethod, ThenableResolve } from './types.js'; +import { HttpMethod, ThenableReject, ThenableResolve } from './types.js'; import { SageHttpRequest } from './SageHttpRequest.js'; import { Readable } from 'node:stream'; import { Client, FormData } from 'undici'; @@ -267,7 +267,10 @@ export class Sage { return this; } - async then(resolve: ThenableResolve): Promise { + async then( + resolve: ThenableResolve, + reject: ThenableReject + ): Promise { // Wait for all deferred promises to resolve await Promise.all(this.deferredPromises); @@ -307,9 +310,11 @@ export class Sage { cookies: parseSetCookieHeader(res.headers['set-cookie']) } satisfies SageHttpResponse); } catch (e) { - throw new SageException( - `Failed to make a request to the underlying server, please take a look at the upstream error for more details: `, - e + reject( + new SageException( + `Failed to make a request to the underlying server, please take a look at the upstream error for more details: `, + e + ) ); } finally { // If there is a dedicated server, skip its shutdown. User is responsible for it.