Skip to content

Commit

Permalink
add the endpoint to the error data to enrich the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Dec 20, 2024
1 parent aa7b14d commit 9522e2c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions connectors/src/connectors/zendesk/lib/zendesk_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import { ZendeskBrandResource } from "@connectors/resources/zendesk_resources";
const ZENDESK_RATE_LIMIT_MAX_RETRIES = 5;
const ZENDESK_RATE_LIMIT_TIMEOUT_SECONDS = 60;

function getEndpointFromZendeskUrl(url: string): string {
return url.replace(/^https?:\/\/(.*)\.zendesk\.com(.*)/, "$2");
}

export function createZendeskClient({
accessToken,
subdomain,
Expand Down Expand Up @@ -162,15 +166,15 @@ async function fetchFromZendeskWithRetries({
throw new ZendeskApiError(
"Error parsing Zendesk API response",
rawResponse.status,
rawResponse
{ rawResponse, endpoint: getEndpointFromZendeskUrl(url) }
);
}
if (!rawResponse.ok) {
throw new ZendeskApiError(
"Zendesk API error.",
rawResponse.status,
response
);
throw new ZendeskApiError("Zendesk API error.", rawResponse.status, {
response,
rawResponse,
endpoint: getEndpointFromZendeskUrl(url),
});
}

return response;
Expand Down

0 comments on commit 9522e2c

Please sign in to comment.