From 9522e2c65871de7100aec087f52f0d3c8a3dca6b Mon Sep 17 00:00:00 2001 From: Aubin Date: Fri, 20 Dec 2024 16:52:49 +0100 Subject: [PATCH] add the endpoint to the error data to enrich the logs --- .../src/connectors/zendesk/lib/zendesk_api.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/connectors/src/connectors/zendesk/lib/zendesk_api.ts b/connectors/src/connectors/zendesk/lib/zendesk_api.ts index 7dba68f1851f..8800e5c0c84e 100644 --- a/connectors/src/connectors/zendesk/lib/zendesk_api.ts +++ b/connectors/src/connectors/zendesk/lib/zendesk_api.ts @@ -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, @@ -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;