Skip to content

Commit f62d59a

Browse files
committed
fix(zerobounce): handle 200-status API errors and guard JSON parsing
1 parent bcb9f47 commit f62d59a

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

apps/sim/tools/zerobounce/get_credits.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ export const getCreditsTool: ToolConfig<ZeroBounceGetCreditsParams, ZeroBounceGe
2828
},
2929

3030
transformResponse: async (response: Response) => {
31-
if (!response.ok) {
31+
const data = await response.json().catch(() => ({}))
32+
// ZeroBounce returns HTTP 200 with an `{ error }` envelope on auth failure,
33+
// so detect API-level errors from the body, not just the HTTP status.
34+
const errorMessage =
35+
typeof data === 'object' && data !== null && typeof data.error === 'string'
36+
? data.error
37+
: ''
38+
if (!response.ok || errorMessage.length > 0) {
3239
return {
3340
success: false,
34-
error: `ZeroBounce API error: ${response.status} ${response.statusText}`,
41+
error: errorMessage || `ZeroBounce API error: ${response.status} ${response.statusText}`,
3542
output: { credits: 0 },
3643
}
3744
}
38-
const data = await response.json()
3945
const credits = Number(data.Credits ?? 0)
4046
return {
4147
success: true,

apps/sim/tools/zerobounce/verify_email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const verifyEmailTool: ToolConfig<
5454
output: { email: '', status: '', deliverable: false },
5555
}
5656
}
57-
const data = await response.json()
57+
const data = await response.json().catch(() => ({}))
5858
if (data.error) {
5959
return {
6060
success: false,

0 commit comments

Comments
 (0)