Commit 8e2f6293 authored by Kishore Battula's avatar Kishore Battula
Browse files

Merge branch 'haggarw/FixingExceptionHandlingInCosmosStore' into 'master'

Fixing an Exception Scenario Handling in CosmosStore

See merge request osdu/platform/system/lib/cloud/azure/os-core-lib-azure!21
parents 66a13540 23c62fc3
......@@ -21,7 +21,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging>
<version>0.0.20</version>
<version>0.0.21</version>
<name>core-lib-azure</name>
<properties>
......
......@@ -141,11 +141,13 @@ public class CosmosStore {
} catch (NotFoundException e) {
LOGGER.info(String.format("Unable to find item with ID=%s and PK=%s", id, partitionKey));
return Optional.empty();
} catch (IOException e) {
LOGGER.warning(String.format("Malformed document for item with ID=%s and PK=%s", id, partitionKey));
return Optional.empty();
} catch (CosmosClientException e) {
String errorMessage = "Unexpectedly encountered error calling CosmosDB";
} catch (IOException | CosmosClientException e) {
String errorMessage;
if (e instanceof IOException) {
errorMessage = String.format("Malformed document for item with ID=%s and PK=%s", id, partitionKey);
} else {
errorMessage = "Unexpectedly encountered error calling CosmosDB";
}
LOGGER.log(Level.WARNING, errorMessage, e);
throw new AppException(500, errorMessage, e.getMessage(), e);
}
......
......@@ -137,9 +137,12 @@ class CosmosStoreTest {
}
@Test
void findItem_returnsEmpty_ifMalformedDocument() throws IOException {
void findItem_throws500_ifMalformedDocument() throws IOException {
doThrow(IOException.class).when(cosmosItemProperties).getObject(any());
assertFalse(cosmosStore.findItem(DATA_PARTITION_ID, COSMOS_DB, COLLECTION, ID, PARTITION_KEY, String.class).isPresent());
AppException exception = assertThrows(AppException.class, () -> {
cosmosStore.findItem(DATA_PARTITION_ID, COSMOS_DB, COLLECTION, ID, PARTITION_KEY, String.class);
});
assertEquals(500, exception.getError().getCode());
}
@Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment