Skip to content

Commit

Permalink
Error message to please management (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa authored Jan 28, 2025
1 parent 1d68dbb commit ca6cd37
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,42 @@ public InputStream read(BucketName bucketName, BlobId blobId) throws ObjectStore
try {
return primaryBlobStoreDAO.read(bucketName, blobId);
} catch (Exception ex) {
InputStream inputStream = secondaryBlobStoreDAO.read(withSuffix(bucketName), blobId);
LOGGER.warn("Fail to read from the first blob store with bucket name {} and blobId {}. Use second blob store", bucketName.asString(), blobId.asString(), ex);
return inputStream;
try {
InputStream inputStream = secondaryBlobStoreDAO.read(withSuffix(bucketName), blobId);
LOGGER.warn("Fail to read from the first blob store with bucket name {} and blobId {}. Use second blob store", bucketName.asString(), blobId.asString(), ex);
return inputStream;
} catch (Exception ex2) {
if (ex instanceof ObjectNotFoundException && ex2 instanceof ObjectNotFoundException) {
throw ex;
}
throw new ObjectStoreException("Failure to read " + blobId.asString() + " in bucket " + bucketName.asString() + " on both blobstores, first error:", ex);
}
}
}

@Override
public Mono<InputStream> readReactive(BucketName bucketName, BlobId blobId) {
return Mono.from(primaryBlobStoreDAO.readReactive(bucketName, blobId))
.onErrorResume(ex -> Mono.from(secondaryBlobStoreDAO.readReactive(withSuffix(bucketName), blobId))
.onErrorResume(ex2 -> {
if (ex instanceof ObjectNotFoundException && ex2 instanceof ObjectNotFoundException) {
return Mono.error(ex);
}
return Mono.error(new ObjectStoreException("Failure to read " + blobId.asString() + " in bucket " + bucketName.asString() + " on both blobstores, first error:", ex));
})
.doOnSuccess(any -> LOGGER.warn("Fail to read from the first blob store with bucket name {} and blobId {}. Use second blob store", bucketName.asString(), blobId.asString(), ex)));
}

@Override
public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
return Mono.from(primaryBlobStoreDAO.readBytes(bucketName, blobId))
.onErrorResume(ex -> Mono.from(secondaryBlobStoreDAO.readBytes(withSuffix(bucketName), blobId))
.onErrorResume(ex2 -> {
if (ex instanceof ObjectNotFoundException && ex2 instanceof ObjectNotFoundException) {
return Mono.error(ex);
}
return Mono.error(new ObjectStoreException("Failure to read " + blobId.asString() + " in bucket " + bucketName.asString() + " on both blobstores, first error:", ex));
})
.doOnSuccess(any -> LOGGER.warn("Fail to read from the first blob store with bucket name {} and blobId {}. Use second blob store", bucketName.asString(), blobId.asString(), ex)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public void readReactiveShouldThrowExceptionWhenBothBlobStoreIsDown() {
secondaryS3.pause();

assertThatThrownBy(() -> Mono.from(testee.readReactive(TEST_BUCKET_NAME, TEST_BLOB_ID)).block())
.isInstanceOf(SdkClientException.class)
.hasMessage("Unable to execute HTTP request: Read timed out");
.isInstanceOf(ObjectStoreException.class)
.hasStackTraceContaining("Unable to execute HTTP request: Read timed out");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.james.blob.api.BlobStoreDAO;
import org.apache.james.blob.api.BlobStoreDAOContract;
import org.apache.james.blob.api.BucketName;
import org.apache.james.blob.api.ObjectNotFoundException;
import org.apache.james.blob.api.ObjectStoreException;
import org.apache.james.blob.api.TestBlobId;
import org.apache.james.blob.objectstorage.aws.AwsS3AuthConfiguration;
Expand Down Expand Up @@ -181,8 +182,8 @@ public void readReactiveShouldThrowExceptionWhenBothBlobStoreIsDown() {
secondaryS3.pause();

assertThatThrownBy(() -> Mono.from(testee.readReactive(TEST_BUCKET_NAME, TEST_BLOB_ID)).block())
.isInstanceOf(SdkClientException.class)
.hasMessage("Unable to execute HTTP request: Read timed out");
.isInstanceOf(ObjectStoreException.class)
.hasStackTraceContaining("Unable to execute HTTP request: Read timed out");
}

@Test
Expand Down

0 comments on commit ca6cd37

Please sign in to comment.