Skip to content
Snippets Groups Projects
Commit 9ef8f4b6 authored by Alok Joshi's avatar Alok Joshi
Browse files

handle schema processing exception explicitly

parent 30c15b32
No related branches found
No related tags found
2 merge requests!346Merge branch 'aws-integration' into 'master',!293Handle schema processing exception explicitly
Pipeline #97144 failed
......@@ -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(
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment