diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCore.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCore.java index c34001666b0c993dae73df6d792caa8d93e6067a..39f5a76b950163f1b283ccd9d8c5adc96a1e5b79 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCore.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCore.java @@ -20,6 +20,7 @@ import javassist.NotFoundException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -74,6 +75,12 @@ public class GlobalExceptionMapperCore extends ResponseEntityExceptionHandler { } } + @ExceptionHandler(SchemaProcessingException.class) + public ResponseEntity<Object> handleSchemaProcessingException(SchemaProcessingException e) { + return this.getErrorResponse( + new AppException(HttpStatus.BAD_REQUEST.value(), "Error processing schema.", e.getMessage(), e)); + } + @ExceptionHandler(Exception.class) protected ResponseEntity<Object> handleGeneralException(Exception e) { return this.getErrorResponse( diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCoreTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCoreTest.java index 992c0a01fea9b1892e20eaaa31b5674028741a85..1877df26e55b971991b6f222cc28a49926426c0f 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCoreTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/error/GlobalExceptionMapperCoreTest.java @@ -23,6 +23,7 @@ import org.mockito.Mock; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.RequestStatus; +import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.ResponseEntity; import org.springframework.security.access.AccessDeniedException; @@ -107,4 +108,12 @@ public class GlobalExceptionMapperCoreTest { ResponseEntity response = this.sut.handleIOException(ioException); assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, response.getStatusCodeValue()); } + + @Test + public void should_returnAppException_when_SchemaProcessingExceptionIsThrown() { + SchemaProcessingException schemaProcessingException = new SchemaProcessingException("error processing schema"); + + ResponseEntity response = this.sut.handleSchemaProcessingException(schemaProcessingException); + assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCodeValue()); + } } \ No newline at end of file