Skip to content

Commit

Permalink
fix: throw should reject in thenables
Browse files Browse the repository at this point in the history
  • Loading branch information
eddienubes committed Aug 24, 2024
1 parent ca13704 commit f257d79
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Sage.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -267,7 +267,10 @@ export class Sage {
return this;
}

async then(resolve: ThenableResolve<SageHttpResponse>): Promise<void> {
async then(
resolve: ThenableResolve<SageHttpResponse>,
reject: ThenableReject
): Promise<void> {
// Wait for all deferred promises to resolve
await Promise.all(this.deferredPromises);

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f257d79

Please sign in to comment.