use of org.projectnessie.versioned.BackendLimitExceededException in project nessie by projectnessie.
the class ErrorTestService method unhandledExceptionInTvsStore.
/**
* Throws an exception depending on the parameter.
*
* @return nothing
* @see TestNessieError#unhandledRuntimeExceptionInStore()
* @see TestNessieError#backendThrottledExceptionInStore()
*/
@Path("unhandledExceptionInTvsStore/{exception}")
@GET
@Consumes(MediaType.APPLICATION_JSON)
public String unhandledExceptionInTvsStore(@PathParam("exception") String exception) throws ReferenceNotFoundException {
Exception ex;
switch(exception) {
case "runtime":
ex = new RuntimeException("Store.getValues-throwing");
break;
case "throttle":
ex = new BackendLimitExceededException("Store.getValues-throttled");
break;
default:
throw new IllegalArgumentException("test code error");
}
DatabaseAdapter databaseAdapter = Mockito.mock(DatabaseAdapter.class);
Mockito.when(databaseAdapter.namedRefs(Mockito.any())).thenThrow(ex);
PersistVersionStore<BaseContent, CommitMessage, BaseContent.Type> tvs = new PersistVersionStore<>(databaseAdapter, SimpleStoreWorker.INSTANCE);
try (Stream<ReferenceInfo<CommitMessage>> refs = tvs.getNamedRefs(GetNamedRefsParams.DEFAULT)) {
refs.forEach(ref -> {
});
}
return "we should not get here";
}
use of org.projectnessie.versioned.BackendLimitExceededException 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);
}
Aggregations