Search in sources :

Example 1 with ErrorReportException

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());
}
Also used : ErrorReportException(bio.terra.common.exception.ErrorReportException) SamInternalServerErrorException(bio.terra.common.sam.exception.SamInternalServerErrorException) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 2 with ErrorReportException

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);
    }
}
Also used : ErrorReportException(bio.terra.common.exception.ErrorReportException) ExceptionSerializerException(bio.terra.workspace.service.job.exception.ExceptionSerializerException) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JobResponseException(bio.terra.workspace.service.job.exception.JobResponseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ExceptionSerializerException(bio.terra.workspace.service.job.exception.ExceptionSerializerException) ErrorReportException(bio.terra.common.exception.ErrorReportException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ErrorReportException (bio.terra.common.exception.ErrorReportException)2 SamInternalServerErrorException (bio.terra.common.sam.exception.SamInternalServerErrorException)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 ExceptionSerializerException (bio.terra.workspace.service.job.exception.ExceptionSerializerException)1 JobResponseException (bio.terra.workspace.service.job.exception.JobResponseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Test (org.junit.jupiter.api.Test)1