Skip to content

Commit 85a6e17

Browse files
hive-botclaude
andcommitted
fix: set the HTTP status on storage and document download errors
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b0901cb commit 85a6e17

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎deepl-java/src/main/java/com/deepl/api/DeepLClient.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,9 @@ public void uploadTranslationMemoryFile(String uploadUrl, byte[] fileContent, St
15231523
httpClientWrapper.sendAssetPutRequestWithBackoff(uploadUrl, fileContent, contentType);
15241524
if (response.getCode() < 200 || response.getCode() >= 300) {
15251525
throw new DeepLException(
1526-
String.format(
1527-
"Error uploading translation memory file, HTTP status: %d", response.getCode()));
1526+
String.format(
1527+
"Error uploading translation memory file, HTTP status: %d", response.getCode()))
1528+
.setHttpStatusCode(response.getCode());
15281529
}
15291530
}
15301531

@@ -1730,9 +1731,10 @@ public void downloadTranslationMemoryExport(TranslationMemoryJob job, OutputStre
17301731
try (HttpResponseStream response = httpClientWrapper.downloadAssetWithBackoff(downloadUrl)) {
17311732
if (response.getCode() < 200 || response.getCode() >= 300) {
17321733
throw new DeepLException(
1733-
String.format(
1734-
"Error downloading translation memory export, HTTP status: %d",
1735-
response.getCode()));
1734+
String.format(
1735+
"Error downloading translation memory export, HTTP status: %d",
1736+
response.getCode()))
1737+
.setHttpStatusCode(response.getCode());
17361738
}
17371739
assert response.getBody() != null;
17381740
StreamUtil.transferTo(response.getBody(), outputStream);

‎deepl-java/src/main/java/com/deepl/api/Translator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ private void checkResponse(HttpResponseStream response) throws DeepLException {
10621062
return;
10631063
}
10641064
if (response.getBody() == null) {
1065-
throw new DeepLException("response stream is empty");
1065+
throw new DeepLException("response stream is empty").setHttpStatusCode(response.getCode());
10661066
}
10671067
checkResponse(response.toStringResponse(), true, false);
10681068
}

‎deepl-java/src/offlineTest/java/com/deepl/api/TranslationMemoriesTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ void throwsDeepLExceptionWhenTheUploadIsRejected() {
251251
client.uploadTranslationMemoryFile(
252252
storageUrl(), new byte[] {1}, "application/xml"));
253253
assertTrue(thrown.getMessage().contains("HTTP status: 403"));
254+
assertEquals(403, thrown.getHttpStatusCode());
255+
assertFalse(thrown.getShouldRetry());
254256
}
255257

256258
@Test
@@ -462,6 +464,8 @@ void leavesNoFileBehindWhenTheDownloadFails() throws Exception {
462464
DeepLException.class,
463465
() -> client.downloadTranslationMemoryExport(completedExport(), output));
464466
assertTrue(thrown.getMessage().contains("HTTP status: 500"));
467+
assertEquals(500, thrown.getHttpStatusCode());
468+
assertTrue(thrown.getShouldRetry());
465469
assertFalse(output.exists());
466470
}
467471

0 commit comments

Comments
 (0)