Skip to content

Commit d5c765a

Browse files
hive-botclaude
andcommitted
fix: reject a 503 document status with DocumentNotReadyError, as released
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 624368a commit d5c765a

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
338338
a status the library did not know made `translateDocument()` and
339339
`translateDocumentWaitUntilDone()` stop polling and reject with
340340
`unknown error`.
341-
- An HTTP 503 response to `translateDocumentGetStatus()` and `getDocumentStatus()`
342-
now throws `DeepLError`; before it threw `DocumentNotReadyError`, which is meant
343-
for document downloads only.
344341
- The document ID is now URL-encoded in the request paths of the document
345342
status and download methods.
346343
- `extraBodyParameters` (and `extraRequestParameters`) of `translateText()` and

‎src/translator.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ export class Translator {
492492
`/v2/document/${encodeURIComponent(handle.documentId)}`,
493493
{ data },
494494
);
495-
await checkStatusCode(statusCode, content);
495+
await checkStatusCode(statusCode, content, false, true);
496496
return parseDocumentStatus(content);
497497
}
498498

‎tests/offline/translateDocument.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,14 @@ describe('Translator.translateDocumentGetStatus', () => {
270270
expect(status.done()).toBe(true);
271271
});
272272

273-
it('throws DeepLError, not DocumentNotReadyError, when the server answers 503', async () => {
273+
it('throws DocumentNotReadyError when the server answers 503', async () => {
274274
nock(serverUrl).post('/v2/document/doc-id').reply(503);
275275

276276
const error = await makeDeeplClient({ maxRetries: 0 })
277277
.translateDocumentGetStatus(handle)
278278
.catch((e) => e);
279279

280-
expect(error).toBeInstanceOf(deepl.DeepLError);
281-
expect(error).not.toBeInstanceOf(deepl.DocumentNotReadyError);
280+
expect(error).toBeInstanceOf(deepl.DocumentNotReadyError);
282281
expect(error.httpStatusCode).toBe(503);
283282
});
284283
});
@@ -325,6 +324,14 @@ describe('Translator.getDocumentStatus', () => {
325324
'Not found, message: nope',
326325
);
327326
});
327+
328+
it('throws DocumentNotReadyError when the server answers 503', async () => {
329+
nock(serverUrl).post('/v2/document/doc-id').reply(503);
330+
331+
await expect(makeTranslator({ maxRetries: 0 }).getDocumentStatus(handle)).rejects.toThrow(
332+
deepl.DocumentNotReadyError,
333+
);
334+
});
328335
});
329336

330337
describe('Translator.translateDocumentWaitUntilDone', () => {

0 commit comments

Comments
 (0)