use of com.thinkbiganalytics.spark.shell.SparkShellSaveException in project kylo by Teradata.
the class SparkShellProxyController method saveError.
/**
* Generates an error response for a failed save.
*
* <p>Example:
* <code>
* throw saveError(Response.Status.BAD_REQUEST, "save.error", e);
* </code></p>
*
* @param status HTTP response status
* @param key resource key or error message
* @param cause the cause
* @return the error response
*/
@Nonnull
private WebApplicationException saveError(@Nonnull final Response.Status status, @Nonnull final String key, @Nullable final Throwable cause) {
// Create entity
final SaveResponse entity = new SaveResponse();
entity.setId(cause instanceof SparkShellSaveException ? ((SparkShellSaveException) cause).getId() : null);
entity.setStatus(SaveResponse.Status.ERROR);
try {
entity.setMessage(STRINGS.getString(key));
} catch (final MissingResourceException e) {
log.warn("Missing resource message: {}", key, e);
entity.setMessage(key);
}
// Generate the response
final Response response = Response.status(status).entity(entity).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
if (cause != null) {
return new WebApplicationException(cause, response);
} else {
return new WebApplicationException(response);
}
}
use of com.thinkbiganalytics.spark.shell.SparkShellSaveException in project kylo by Teradata.
the class SparkShellProxyController method getSaveResponse.
/**
* Gets the save response from the specified supplier.
*/
@Nonnull
private Response getSaveResponse(@Nonnull final Supplier<Optional<SaveResponse>> supplier) {
// Get the result
final Optional<SaveResponse> response;
try {
response = supplier.get();
} catch (final SparkShellSaveException e) {
final String message = (e.getMessage() != null) ? EXCEPTION.matcher(e.getMessage()).replaceAll("") : SparkShellProxyResources.SAVE_ERROR;
throw saveError(Response.Status.INTERNAL_SERVER_ERROR, message, e);
} catch (final Exception e) {
throw saveError(Response.Status.INTERNAL_SERVER_ERROR, SparkShellProxyResources.SAVE_ERROR, e);
}
// Return response
final SaveResponse saveResponse = response.orElseThrow(() -> transformError(Response.Status.NOT_FOUND, SparkShellProxyResources.SAVE_NOT_FOUND, null));
return Response.ok(saveResponse).build();
}
Aggregations