Skip to content

Commit

Permalink
Refactor deepLGetLanguages()
Browse files Browse the repository at this point in the history
  • Loading branch information
ttsukagoshi committed Feb 20, 2024
1 parent e26dd60 commit d979f99
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/sheetsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,13 @@ export function deepLGetLanguages(
const apiKey = getDeepLApiKey();
const baseUrl = getDeepLApiBaseUrl(apiKey);
// Call the DeepL API
const url = baseUrl + endpoint + `?auth_key=${apiKey}&type=${type}`;
const response = handleDeepLErrors(
UrlFetchApp.fetch(url, { muteHttpExceptions: true }),
);
const url = baseUrl + endpoint + `?type=${type}`;
const options: GoogleAppsScript.URL_Fetch.URLFetchRequestOptions = {
method: 'get',
headers: { Authorization: `DeepL-Auth-Key ${apiKey}` },
muteHttpExceptions: true,
};
const response = handleDeepLErrors(UrlFetchApp.fetch(url, options));

return JSON.parse(response.getContentText()) as DeepLSupportedLanguages[];
}
Expand Down

0 comments on commit d979f99

Please sign in to comment.