diff --git a/src/client.ts b/src/client.ts index 6dd9242..1661791 100644 --- a/src/client.ts +++ b/src/client.ts @@ -110,7 +110,7 @@ export class HttpClient { options: SendRequestOptions, ): AxiosRequestConfig { const headers = Object.assign({}, this.headers, options.headers); - console.log(`isDeepL: ${isDeepL}`); + logDebug(`isDeepL: ${isDeepL}`); const axiosRequestConfig: AxiosRequestConfig = { url: isDeepL ? url : undefined, @@ -152,7 +152,7 @@ export class HttpClient { * @param url Path to endpoint, excluding base server URL if DeepL API request, including base server URL if a webpage. * @param options Additional options controlling request. * @param responseAsStream Set to true if the return type is IncomingMessage. - * @return Fulfills with status code and response (as text or stream). + * @return Fulfills with status code, content type, and response (as text or stream). */ async sendRequestWithBackoff( method: HttpMethod, @@ -182,6 +182,11 @@ export class HttpClient { isDeepLUrl, options, ); + + if (!isDeepLUrl && axiosRequestConfig.headers) { + delete axiosRequestConfig.headers.Authorization; + } + try { response = await HttpClient.sendAxiosRequest(axiosRequestConfig); error = undefined; @@ -251,7 +256,11 @@ export class HttpClient { } } - return { statusCode: response.status, content: response.data, contentType }; + return { + statusCode: response.status, + content: response.data, + contentType: contentType, + }; } catch (axios_error_raw) { const axiosError = axios_error_raw as AxiosError; const message: string = axiosError.message || ''; diff --git a/src/errors.ts b/src/errors.ts index 17f5baf..78325f0 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -41,3 +41,5 @@ export class DocumentTranslationError extends DeepLError { export class GlossaryNotFoundError extends DeepLError {} export class DocumentNotReadyError extends DeepLError {} + +export class WebsiteDownloadError extends DeepLError {} diff --git a/src/index.ts b/src/index.ts index bd3a28c..6f61dfe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ import { GlossaryNotFoundError, QuotaExceededError, TooManyRequestsError, + WebsiteDownloadError, } from './errors'; import { GlossaryEntries } from './glossaryEntries'; import { @@ -1062,7 +1063,7 @@ export class Translator { await checkStatusCode(statusCode, content); if (!contentType?.includes('text/html')) { - throw new Error('URL to translate must return HTML'); + throw new WebsiteDownloadError('URL to translate must return HTML'); } return content;