Skip to content

Commit

Permalink
[gh-#687] variable for number of retries, fix error code and update m…
Browse files Browse the repository at this point in the history
…essaging
  • Loading branch information
khaliqgant committed Sep 15, 2023
1 parent 1de9c7e commit 4753051
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/shared/lib/services/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type { SyncResult, NangoSyncWebhookBody } from '../models/Sync';
import environmentService from './environment.service.js';
import { createActivityLogMessage } from './activity/activity.service.js';

const RETRY_ATTEMPTS = 10;

class WebhookService {
private retry = async (activityLogId: number, error: AxiosError, attemptNumber: number): Promise<boolean> => {
if (error?.response && (error?.response?.status < 200 || error?.response?.status > 300)) {
if (error?.response && (error?.response?.status < 200 || error?.response?.status >= 300)) {
const content = `Webhook response received an ${
error?.response?.status || error?.code
} error, retrying with exponential backoffs for a total of ${attemptNumber} times`;
} error, retrying with exponential backoffs for ${attemptNumber} out of ${RETRY_ATTEMPTS} times`;

await createActivityLogMessage({
level: 'error',
Expand Down Expand Up @@ -79,7 +81,7 @@ class WebhookService {
() => {
return axios.post(webhookUrl, body);
},
{ numOfAttempts: 5, retry: this.retry.bind(this, activityLogId) }
{ numOfAttempts: RETRY_ATTEMPTS, retry: this.retry.bind(this, activityLogId) }
);

if (response.status >= 200 && response.status < 300) {
Expand Down

0 comments on commit 4753051

Please # to comment.