Skip to content

Commit dde7fbe

Browse files
authored
feat(sdk): handle errors from i18n when streaming (#574)
1 parent d968aa6 commit dde7fbe

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.changeset/tender-suns-cry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"lingo.dev": patch
3+
"@lingo.dev/_sdk": patch
4+
---
5+
6+
handle errors from i18n when streaming

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ async function retryWithExponentialBackoff<T>(
401401
}
402402

403403
function createLocalizationEngineConnection(params: { apiKey: string; apiUrl: string; maxRetries?: number }) {
404-
const replexicaEngine = new LingoDotDevEngine({
404+
const engine = new LingoDotDevEngine({
405405
apiKey: params.apiKey,
406406
apiUrl: params.apiUrl,
407407
});
@@ -423,7 +423,7 @@ function createLocalizationEngineConnection(params: { apiKey: string; apiUrl: st
423423
) => {
424424
return retryWithExponentialBackoff(
425425
() =>
426-
replexicaEngine.localizeObject(
426+
engine.localizeObject(
427427
args.processableData,
428428
{
429429
sourceLocale: args.sourceLocale,

packages/sdk/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ export class LingoDotDevEngine {
129129
}
130130

131131
const jsonResponse = await res.json();
132+
133+
// when streaming the error is returned in the response body
134+
if (!jsonResponse.data && jsonResponse.error) {
135+
throw new Error(jsonResponse.error);
136+
}
137+
132138
return jsonResponse.data || {};
133139
}
134140

0 commit comments

Comments
 (0)