Skip to content

Commit d0978af

Browse files
committed
Use onRetryRethrow to rethrow auth errors in batch purl helper
1 parent b242437 commit d0978af

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,6 @@ export class SocketSdk {
400400
readonly #baseUrl: string
401401
readonly #reqOptions: RequestOptions
402402

403-
/**
404-
* @throws {SocketSdkAuthError}
405-
*/
406403
constructor(apiToken: string, options?: SocketSdkOptions | undefined) {
407404
const {
408405
agent: agentOrObj,
@@ -452,7 +449,17 @@ export class SocketSdk {
452449
res = await pRetry(
453450
() => this.#createBatchPurlRequest(queryParams, componentsObj),
454451
{
455-
retries: 4
452+
retries: 4,
453+
onRetryRethrow: true,
454+
onRetry(_attempt, error) {
455+
if (!(error instanceof ResponseError)) {
456+
return
457+
}
458+
const { statusCode } = error.response
459+
if (statusCode === 401 || statusCode === 403) {
460+
throw error
461+
}
462+
}
456463
}
457464
)
458465
} catch (e) {
@@ -476,7 +483,7 @@ export class SocketSdk {
476483
cause: error
477484
})
478485
}
479-
const statusCode = error.response.statusCode
486+
const { statusCode } = error.response
480487
if (statusCode! >= 500) {
481488
throw new Error(`Socket API server error (${statusCode})`, {
482489
cause: error

0 commit comments

Comments
 (0)