Skip to content

Commit 9fefb08

Browse files
hive-botclaude
andcommitted
fix: throw DeepLError on HTTP 503 from the document status request
The status request mapped HTTP 503 to DocumentNotReadyError, which is meant for document downloads only. It now throws DeepLError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4821fc1 commit 9fefb08

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
187187
a status the library did not know made `translateDocument()` and
188188
`translateDocumentWaitUntilDone()` stop polling and reject with
189189
`unknown error`.
190+
- An HTTP 503 response to `translateDocumentGetStatus()` and `getDocumentStatus()`
191+
now throws `DeepLError`; before it threw `DocumentNotReadyError`, which is meant
192+
for document downloads only.
190193
- `extraBodyParameters` (and `extraRequestParameters`) of `translateText()` and
191194
`uploadDocument()`/`translateDocument()` now replace every parameter of the same
192195
name set by the library. Before, parameters appended after the languages and

‎src/translator.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ export class Translator {
476476
`/v2/document/${handle.documentId}`,
477477
{ data },
478478
);
479-
await checkStatusCode(statusCode, content, false, true);
479+
await checkStatusCode(statusCode, content);
480480
return parseDocumentStatus(content);
481481
}
482482

‎tests/offline/translateDocument.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ describe('Translator.translateDocumentGetStatus', () => {
218218

219219
expect([status.status, status.ok(), status.done()]).toEqual([expected, true, false]);
220220
});
221+
222+
it('throws DeepLError, not DocumentNotReadyError, when the server answers 503', async () => {
223+
nock(serverUrl).post('/v2/document/doc-id').reply(503);
224+
225+
const error = await makeDeeplClient({ maxRetries: 0 })
226+
.translateDocumentGetStatus(handle)
227+
.catch((e) => e);
228+
229+
expect(error).toBeInstanceOf(deepl.DeepLError);
230+
expect(error).not.toBeInstanceOf(deepl.DocumentNotReadyError);
231+
expect(error.httpStatusCode).toBe(503);
232+
});
221233
});
222234

223235
describe('Translator.getDocumentStatus', () => {

0 commit comments

Comments
 (0)