use of bio.terra.common.exception.ErrorReportException in project terra-workspace-manager by DataBiosphere.
the class WorkspaceServiceTest method testHandlesSamError.
@Test
void testHandlesSamError() throws Exception {
String apiErrorMsg = "test";
ErrorReportException testex = new SamInternalServerErrorException(apiErrorMsg);
doThrow(testex).when(mockSamService).createWorkspaceWithDefaults(any(), any());
ErrorReportException exception = assertThrows(SamInternalServerErrorException.class, () -> workspaceService.createWorkspace(defaultRequestBuilder(UUID.randomUUID()).build(), USER_REQUEST));
assertEquals(apiErrorMsg, exception.getMessage());
}
use of bio.terra.common.exception.ErrorReportException in project terra-workspace-manager by DataBiosphere.
the class StairwayExceptionSerializer method serialize.
@Override
public String serialize(Exception rawException) {
if (rawException == null) {
return StringUtils.EMPTY;
}
Exception exception = rawException;
// Wrap non-runtime exceptions so they can be rethrown later
if (!(exception instanceof RuntimeException)) {
exception = new JobResponseException(exception.getMessage(), exception);
}
StairwayExceptionFields fields = new StairwayExceptionFields().setClassName(exception.getClass().getName()).setMessage(exception.getMessage());
if (exception instanceof ErrorReportException) {
fields.setApiErrorReportException(true).setErrorDetails(((ErrorReportException) exception).getCauses()).setErrorCode(((ErrorReportException) exception).getStatusCode().value());
} else {
fields.setApiErrorReportException(false);
}
try {
return objectMapper.writeValueAsString(fields);
} catch (JsonProcessingException ex) {
// JSON processing to fail.
throw new ExceptionSerializerException("This should never happen", ex);
}
}
Aggregations