Skip to content

Commit 89c1b68

Browse files
authored
Merge pull request #2670 from 1000hz/headers-dont-throw-validation-error-w-custom-fetch
chore(client): don't throw a validation error for missing auth headers if using custom fetch
2 parents 82e1127 + 109846d commit 89c1b68

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export abstract class APIClient {
234234
/**
235235
* Override this to add your own headers validation:
236236
*/
237-
protected validateHeaders(headers: Headers, customHeaders: Headers) {}
237+
protected validateHeaders(headers: Headers, customHeaders: Headers, usingCustomFetch: boolean) {}
238238

239239
protected defaultIdempotencyKey(): string {
240240
return `stainless-node-retry-${uuid4()}`;
@@ -397,7 +397,7 @@ export abstract class APIClient {
397397
reqHeaders['x-stainless-timeout'] = String(options.timeout);
398398
}
399399

400-
this.validateHeaders(reqHeaders, headers);
400+
this.validateHeaders(reqHeaders, headers, this.fetch !== fetch);
401401

402402
return reqHeaders;
403403
}

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ export class Cloudflare extends Core.APIClient {
381381
};
382382
}
383383

384-
protected override validateHeaders(headers: Core.Headers, customHeaders: Core.Headers) {
384+
protected override validateHeaders(
385+
headers: Core.Headers,
386+
customHeaders: Core.Headers,
387+
usingCustomFetch: boolean,
388+
) {
385389
if (this.apiEmail && headers['x-auth-email']) {
386390
return;
387391
}
@@ -410,6 +414,11 @@ export class Cloudflare extends Core.APIClient {
410414
return;
411415
}
412416

417+
// we can't check for the presence of the headers with a custom fetch implementation, so we shouldn't throw an error
418+
if (usingCustomFetch) {
419+
return;
420+
}
421+
413422
throw new Error(
414423
'Could not resolve authentication method. Expected one of apiEmail, apiKey, apiToken or userServiceKey to be set. Or for one of the "X-Auth-Email", "X-Auth-Key", "Authorization" or "X-Auth-User-Service-Key" headers to be explicitly omitted',
415424
);

0 commit comments

Comments
 (0)