use of com.bakdata.quick.common.api.model.ErrorMessage in project quick by bakdata.
the class ControllerUpdateSchemaTest method returnsErrorForWrongBody.
@Test
void returnsErrorForWrongBody() {
final HttpRequest<?> httpRequest = HttpRequest.create(HttpMethod.POST, "/control/schema").body(new SchemaData("test"));
assertThatExceptionOfType(HttpClientResponseException.class).isThrownBy(() -> this.httpClient.retrieve(httpRequest).blockingFirst()).isInstanceOfSatisfying(HttpClientResponseException.class, ex -> assertThat(extractErrorMessage(ex)).isPresent().get().hasFieldOrPropertyWithValue("type", "errors/clientError").hasFieldOrPropertyWithValue("title", "Bad Request").extracting(ErrorMessage::getDetail, InstanceOfAssertFactories.STRING).startsWith("Could not parse GraphQL schema:"));
}
use of com.bakdata.quick.common.api.model.ErrorMessage in project quick by bakdata.
the class GeneralExceptionHandler method handle.
@Override
public HttpResponse<ErrorMessage> handle(final HttpRequest request, final Exception exception) {
log.error("Unexpected and not handled error: ", exception);
final String detail = "An unexpected error occurred:" + exception.getMessage();
final ErrorMessage error = HttpStatusError.toError(HttpStatus.INTERNAL_SERVER_ERROR, request.getPath(), detail);
return HttpResponse.<ErrorMessage>serverError().body(error);
}
use of com.bakdata.quick.common.api.model.ErrorMessage in project quick by bakdata.
the class SchemaRegistryExceptionHandler method handle.
@Override
public HttpResponse<ErrorMessage> handle(final HttpRequest request, final RestClientException exception) {
// strip error code as it is not relevant for user
final String message;
if (exception.getMessage() != null) {
final int i = exception.getMessage().indexOf("; error code: ");
message = exception.getMessage().substring(0, i);
} else {
message = UNKNOWN_ERROR;
}
final ErrorMessage errorMessage = ErrorMessage.builder().type("error/schema").code(exception.getStatus()).title("Schema Error").detail(message).uriPath(request.getPath()).build();
return HttpResponse.<ErrorMessage>status(HttpStatus.valueOf(exception.getStatus())).body(errorMessage);
}
use of com.bakdata.quick.common.api.model.ErrorMessage in project quick by bakdata.
the class AvroExceptionHandler method handle.
@Override
public HttpResponse<ErrorMessage> handle(final HttpRequest request, final AvroRuntimeException exception) {
final ErrorMessage errorMessage;
final String detail;
if (exception instanceof AvroTypeException || exception instanceof AvroMissingFieldException || exception instanceof UnresolvedUnionException) {
detail = String.format("Could not parse input: %s", exception.getMessage());
} else if (exception instanceof AvroConversionException) {
detail = String.format("An Error occurred during conversion of the Avro: %s", exception.getMessage());
} else {
errorMessage = HttpStatusError.toError(HttpStatus.INTERNAL_SERVER_ERROR, request.getPath(), exception.getMessage());
return HttpResponse.<ErrorMessage>status(HttpStatus.valueOf(errorMessage.getCode())).body(errorMessage);
}
errorMessage = HttpStatusError.toError(HttpStatus.BAD_REQUEST, request.getPath(), detail);
return HttpResponse.<ErrorMessage>status(HttpStatus.valueOf(errorMessage.getCode())).body(errorMessage);
}
use of com.bakdata.quick.common.api.model.ErrorMessage in project quick by bakdata.
the class JsonErrorExceptionHandler method doFilter.
@Override
public Publisher<MutableHttpResponse<?>> doFilter(final HttpRequest<?> request, final ServerFilterChain chain) {
return Flowable.fromPublisher(chain.proceed(request)).map(response -> {
// check all 4xx and 5xx (client and server errors)
if (response.getStatus().getCode() >= 400) {
final Optional<JsonError> body = response.getBody(JsonError.class);
if (body.isPresent()) {
log.trace("Convert JSON error to custom error message");
final JsonError jsonError = body.get();
final ErrorMessage errorMessage = HttpStatusError.toError(response.getStatus(), request.getPath(), jsonError.getMessage());
return HttpResponse.status(response.getStatus()).body(errorMessage);
}
}
return response;
});
}
Aggregations