Skip to content

Commit a143cdb

Browse files
CopilotAlCalzone
andauthored
fix: increase HTTP request timeouts for ioBroker translations (#195)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: AlCalzone <17641229+AlCalzone@users.noreply.github.com>
1 parent fc73a75 commit a143cdb

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

packages/plugin-iobroker/src/translate.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe("translateText", () => {
4141
"https://translator.iobroker.in/translator",
4242
expect.objectContaining({
4343
body: expect.any(URLSearchParams),
44+
timeout: 120000,
4445
}),
4546
);
4647

@@ -79,6 +80,7 @@ describe("translateText", () => {
7980
"https://api-free.deepl.com/v2/translate",
8081
expect.objectContaining({
8182
body: expect.any(URLSearchParams),
83+
timeout: 30000,
8284
}),
8385
);
8486

packages/plugin-iobroker/src/translate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import ky from "ky";
22

33
const ioBrokerUrl = "https://translator.iobroker.in/translator";
4+
const defaultTimeout = 30_000;
5+
const ioBrokerTimeout = 120_000;
46

57
// DeepL language mappings - from DeepL API codes to ioBroker expected codes
68
const deeplLanguageMap: Record<string, string> = {
@@ -37,6 +39,7 @@ async function translateWithDeepL(textEN: string, apiKey: string): Promise<Recor
3739
// First, test with one language to validate API key
3840
const response = await ky
3941
.post(baseUrl, {
42+
timeout: defaultTimeout,
4043
body: new URLSearchParams({
4144
text: textEN,
4245
source_lang: "EN",
@@ -56,6 +59,7 @@ async function translateWithDeepL(textEN: string, apiKey: string): Promise<Recor
5659
try {
5760
const resp = await ky
5861
.post(baseUrl, {
62+
timeout: defaultTimeout,
5963
body: new URLSearchParams({
6064
text: textEN,
6165
source_lang: "EN",
@@ -89,6 +93,7 @@ async function translateWithIoBroker(textEN: string): Promise<Record<string, str
8993
text: textEN,
9094
together: "true",
9195
}),
96+
timeout: ioBrokerTimeout,
9297
})
9398
.json();
9499
}

0 commit comments

Comments
 (0)