Skip to content

SPR-15404 fine-grained http rest exceptions #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,77 @@ public void handleError(ClientHttpResponse response) throws IOException {
protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
switch (statusCode.series()) {
case CLIENT_ERROR:
handleClientError(response, statusCode);
return;
case SERVER_ERROR:
handleServerError(response, statusCode);
return;
default:
throw new UnknownHttpStatusCodeException(statusCode.value(), response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
}
}

private void handleClientError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
switch (statusCode) {
case BAD_REQUEST:
throw new HttpClientErrorException.BadRequest(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case UNAUTHORIZED:
throw new HttpClientErrorException.Unauthorized(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case FORBIDDEN:
throw new HttpClientErrorException.Forbidden(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case NOT_FOUND:
throw new HttpClientErrorException.NotFound(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case METHOD_NOT_ALLOWED:
throw new HttpClientErrorException.MethodNotAllowed(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case NOT_ACCEPTABLE:
throw new HttpClientErrorException.NotAcceptable(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case CONFLICT:
throw new HttpClientErrorException.Conflict(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case GONE:
throw new HttpClientErrorException.Gone(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case UNSUPPORTED_MEDIA_TYPE:
throw new HttpClientErrorException.UnsupportedMediaType(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case TOO_MANY_REQUESTS:
throw new HttpClientErrorException.TooManyRequests(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case UNPROCESSABLE_ENTITY:
throw new HttpClientErrorException.UnprocessableEntity(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
default:
throw new HttpClientErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case SERVER_ERROR:
throw new HttpServerErrorException(statusCode, response.getStatusText(),
}
}

private void handleServerError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
switch (statusCode) {
case INTERNAL_SERVER_ERROR:
throw new HttpServerErrorException.InternalServerError(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case NOT_IMPLEMENTED:
throw new HttpServerErrorException.NotImplemented(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case BAD_GATEWAY:
throw new HttpServerErrorException.BadGateway(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case SERVICE_UNAVAILABLE:
throw new HttpServerErrorException.ServiceUnavailable(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case GATEWAY_TIMEOUT:
throw new HttpServerErrorException.GatewayTimeout(response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
default:
throw new UnknownHttpStatusCodeException(statusCode.value(), response.getStatusText(),
throw new HttpServerErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
}
}
Expand Down
Loading