Skip to content

Commit

Permalink
fix: add timeout handling for Brevo API health check
Browse files Browse the repository at this point in the history
  • Loading branch information
loicguillois committed Jan 6, 2025
1 parent 373ec3e commit da5cf04
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/healthcheck/src/checks/brevo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ export function brevoCheck(apiKey: string, options?: BrevoCheckOptions): Check {
return Promise.resolve();
}

await fetch('https://api.brevo.com/v3/smtp/statistics/aggregatedReport', {
method: 'GET',
headers: {
accept: 'application/json',
'api-key': apiKey
}
}).then((res) => {
if (res.status !== 200) {
throw new Error('Brevo API is not available');
}
});
try {
await fetch('https://api.brevo.com/v3/smtp/statistics/aggregatedReport', {
method: 'GET',
headers: {
accept: 'application/json',
'api-key': apiKey
},
signal: AbortSignal.timeout(2000),
}).then((res) => {
if (res.status !== 200) {
throw new Error('Brevo API is not available');
}
});
} catch {
throw new Error('Brevo API is not available');
}
}
};
}

0 comments on commit da5cf04

Please sign in to comment.