Skip to content

Commit d2644e2

Browse files
Address PR feedback
1 parent 52b7e36 commit d2644e2

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/client.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class HttpClient {
110110
options: SendRequestOptions,
111111
): AxiosRequestConfig {
112112
const headers = Object.assign({}, this.headers, options.headers);
113-
console.log(`isDeepL: ${isDeepL}`);
113+
logDebug(`isDeepL: ${isDeepL}`);
114114

115115
const axiosRequestConfig: AxiosRequestConfig = {
116116
url: isDeepL ? url : undefined,
@@ -152,7 +152,7 @@ export class HttpClient {
152152
* @param url Path to endpoint, excluding base server URL if DeepL API request, including base server URL if a webpage.
153153
* @param options Additional options controlling request.
154154
* @param responseAsStream Set to true if the return type is IncomingMessage.
155-
* @return Fulfills with status code and response (as text or stream).
155+
* @return Fulfills with status code, content type, and response (as text or stream).
156156
*/
157157
async sendRequestWithBackoff<TContent extends string | IncomingMessage>(
158158
method: HttpMethod,
@@ -182,6 +182,11 @@ export class HttpClient {
182182
isDeepLUrl,
183183
options,
184184
);
185+
186+
if (!isDeepLUrl && axiosRequestConfig.headers) {
187+
delete axiosRequestConfig.headers.Authorization;
188+
}
189+
185190
try {
186191
response = await HttpClient.sendAxiosRequest<TContent>(axiosRequestConfig);
187192
error = undefined;
@@ -251,7 +256,11 @@ export class HttpClient {
251256
}
252257
}
253258

254-
return { statusCode: response.status, content: response.data, contentType };
259+
return {
260+
statusCode: response.status,
261+
content: response.data,
262+
contentType: contentType,
263+
};
255264
} catch (axios_error_raw) {
256265
const axiosError = axios_error_raw as AxiosError;
257266
const message: string = axiosError.message || '';

src/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ export class DocumentTranslationError extends DeepLError {
4141
export class GlossaryNotFoundError extends DeepLError {}
4242

4343
export class DocumentNotReadyError extends DeepLError {}
44+
45+
export class WebsiteDownloadError extends DeepLError {}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
GlossaryNotFoundError,
1212
QuotaExceededError,
1313
TooManyRequestsError,
14+
WebsiteDownloadError,
1415
} from './errors';
1516
import { GlossaryEntries } from './glossaryEntries';
1617
import {
@@ -1062,7 +1063,7 @@ export class Translator {
10621063
await checkStatusCode(statusCode, content);
10631064

10641065
if (!contentType?.includes('text/html')) {
1065-
throw new Error('URL to translate must return HTML');
1066+
throw new WebsiteDownloadError('URL to translate must return HTML');
10661067
}
10671068

10681069
return content;

0 commit comments

Comments
 (0)