use of bio.terra.workspace.service.job.exception.JobResponseException 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);
}
}
use of bio.terra.workspace.service.job.exception.JobResponseException in project terra-workspace-manager by DataBiosphere.
the class JobService method retrieveJobResultWorker.
private <T> JobResultOrException<T> retrieveJobResultWorker(String jobId, Class<T> resultClass) throws StairwayException, InterruptedException {
FlightState flightState = stairwayComponent.get().getFlightState(jobId);
FlightMap resultMap = flightState.getResultMap().orElse(null);
if (resultMap == null) {
throw new InvalidResultStateException("No result map returned from flight");
}
switch(flightState.getFlightStatus()) {
case FATAL:
case ERROR:
if (flightState.getException().isPresent()) {
Exception exception = flightState.getException().get();
if (exception instanceof RuntimeException) {
return new JobResultOrException<T>().exception((RuntimeException) exception);
} else {
return new JobResultOrException<T>().exception(new JobResponseException("wrap non-runtime exception", exception));
}
}
throw new InvalidResultStateException("Failed operation with no exception reported");
case SUCCESS:
return new JobResultOrException<T>().result(resultMap.get(JobMapKeys.RESPONSE.getKeyName(), resultClass));
case RUNNING:
throw new JobNotCompleteException("Attempt to retrieve job result before job is complete; job id: " + flightState.getFlightId());
default:
throw new InvalidResultStateException("Impossible case reached");
}
}
Aggregations