use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.
the class NessieExceptionMapper method toResponse.
@Override
public Response toResponse(Exception exception) {
ErrorCode errorCode;
String message;
if (exception instanceof BaseNessieClientServerException) {
BaseNessieClientServerException e = (BaseNessieClientServerException) exception;
errorCode = e.getErrorCode();
message = exception.getMessage();
} else if (exception.getCause() instanceof BaseNessieClientServerException) {
BaseNessieClientServerException e = (BaseNessieClientServerException) exception.getCause();
errorCode = e.getErrorCode();
message = exception.getCause().getMessage();
} else if (exception instanceof JsonParseException || exception instanceof JsonMappingException || exception instanceof IllegalArgumentException) {
errorCode = ErrorCode.BAD_REQUEST;
message = exception.getMessage();
} else if (exception instanceof BackendLimitExceededException) {
LOGGER.warn("Backend throttled/refused the request: {}", exception.toString());
errorCode = ErrorCode.TOO_MANY_REQUESTS;
message = "Backend store refused to process the request: " + exception;
} else if (exception instanceof AccessControlException) {
errorCode = ErrorCode.FORBIDDEN;
message = exception.getMessage();
} else {
LOGGER.warn("Unhandled exception returned as HTTP/500 to client", exception);
errorCode = ErrorCode.UNKNOWN;
message = Throwables.getCausalChain(exception).stream().map(Throwable::toString).collect(Collectors.joining(", caused by"));
}
return buildExceptionResponse(errorCode, message, exception);
}
use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.
the class NessieViewOperations method drop.
@Override
public void drop(String viewIdentifier) {
reference.checkMutable();
IcebergView existingView = view(toCatalogTableIdentifier(viewIdentifier));
if (existingView == null) {
return;
}
CommitMultipleOperationsBuilder commitBuilderBase = api.commitMultipleOperations().commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg delete view %s", viewIdentifier), catalogOptions)).operation(Operation.Delete.of(NessieUtil.toKey(toCatalogTableIdentifier(viewIdentifier))));
// We try to drop the view. Simple retry after ref update.
try {
Tasks.foreach(commitBuilderBase).retry(5).stopRetryOn(NessieNotFoundException.class).throwFailureWhenFinished().onFailure((o, exception) -> refresh()).run(commitBuilder -> {
Branch branch = commitBuilder.branch(reference.getAsBranch()).commit();
reference.updateReference(branch);
}, BaseNessieClientServerException.class);
} catch (NessieConflictException e) {
LOG.error("Cannot drop view: failed after retry (update ref and retry)", e);
} catch (NessieNotFoundException e) {
LOG.error("Cannot drop view: ref is no longer valid.", e);
} catch (BaseNessieClientServerException e) {
LOG.error("Cannot drop view: unknown error", e);
}
}
Aggregations