Skip to content

Commit

Permalink
[connectors] Add logs on Zendesk API response parsing (#8811)
Browse files Browse the repository at this point in the history
* 🔊 add logs on Zendesk API response parsing

* parse the response as json directly
  • Loading branch information
aubin-tchoi authored Nov 21, 2024
1 parent 6f1afd8 commit 3ac5f7d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions connectors/src/connectors/zendesk/lib/zendesk_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,16 @@ async function fetchFromZendeskWithRetries({
);
}
}
const text = await rawResponse.text();
const response = JSON.parse(text);

let response;
try {
response = await rawResponse.json();
} catch (e) {
logger.error(
{ rawResponse },
"[Zendesk] Error parsing Zendesk API response"
);
throw new Error("Error parsing Zendesk API response");
}
if (!rawResponse.ok) {
if (response.type === "error.list" && response.errors?.length) {
const error = response.errors[0];
Expand All @@ -143,8 +150,8 @@ async function fetchFromZendeskWithRetries({
return null;
}
}
logger.error({ response }, "[Zendesk] Zendesk API error");
throw new Error(`Zendesk API error: ${text}`);
logger.error({ rawResponse }, "[Zendesk] Zendesk API error");
throw new Error("Zendesk API error.");
}

return response;
Expand Down

0 comments on commit 3ac5f7d

Please sign in to comment.