Skip to content

Commit

Permalink
feat: Plat-6104 prevent sdk retries on 500 error (#689)
Browse files Browse the repository at this point in the history
* feat: prevent sdk retries on 500 errors

* chore: remove files

* chore: remove files
  • Loading branch information
zeljkoX authored Feb 5, 2025
1 parent bcfcedf commit 0ff02ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/relayer-signer-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"@openzeppelin/defender-sdk": "2.1.0",
"dotenv": "^16.3.1"
}
}
}
8 changes: 8 additions & 0 deletions packages/base/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ export abstract class BaseApiClient {
throw new Error('API Key is either expired or invalid');
}

// by default no retries on 500 errors except for Cloudflare errors
if (isInternalServerError(error) && !isCloudFlareError(error)) {
throw error;
}

// this means ID token has expired so we'll recreate session and try again
if (isAuthenticationError(error)) {
this.api = undefined;
Expand Down Expand Up @@ -183,6 +188,9 @@ const isAuthenticationError = (axiosError: AxiosError): boolean =>
const isCloudFlareError = (axiosError: AxiosError): boolean =>
axiosError.response?.status === 520 && (axiosError.response?.data as string).includes('Cloudflare');

const isInternalServerError = (axiosError: AxiosError): boolean =>
axiosError.response?.status ? axiosError.response.status >= 500 : false;

export const exponentialDelay = (
retryNumber = 0,
_error: AxiosError | undefined = undefined,
Expand Down

0 comments on commit 0ff02ed

Please sign in to comment.