Skip to content

Commit

Permalink
fix: 400 error
Browse files Browse the repository at this point in the history
  • Loading branch information
ifyour committed Nov 6, 2023
1 parent 5744e1b commit 5e965f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export const API_URL = 'https://www2.deepl.com/jsonrpc';
export const DEFAULT_LANGUAGE = 'AUTO';
export const REQUEST_ALTERNATIVES = 3;

export const DEFAULT_REQUEST_PARAMS = {
text: 'Error: the request was incorrect',
source_lang: DEFAULT_LANGUAGE,
target_lang: DEFAULT_LANGUAGE,
target_lang: 'zh',
};
5 changes: 3 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function query(params: RequestParams) {
'Content-Type': 'application/json; charset=utf-8',
},
method: 'POST',
body: buildRequestBody(Object.assign({}, DEFAULT_REQUEST_PARAMS, params)),
body: buildRequestBody({ ...DEFAULT_REQUEST_PARAMS, ...params }),
});

if (response.ok) {
Expand All @@ -81,10 +81,11 @@ async function query(params: RequestParams) {
return {
id: 42,
code: response.status,
params,
data:
response.status === 429
? 'Too many requests, please try again later.'
: response.statusText || 'Unknown error.',
: 'Unknown error.',
};
}

Expand Down

0 comments on commit 5e965f7

Please sign in to comment.