use of com.netflix.metacat.common.exception.MetacatUnAuthorizedException in project metacat by Netflix.
the class MetacatErrorDecoder method decode.
/**
* {@inheritDoc}
*/
@Override
public Exception decode(final String methodKey, final Response response) {
try {
String message = "";
if (response.body() != null) {
message = Util.toString(response.body().asReader());
try {
final ObjectNode body = metacatJson.parseJsonObject(message);
message = body.path("error").asText();
if (Strings.isNullOrEmpty(message)) {
message = body.path("message").asText("No error message supplied.");
}
} catch (final MetacatJsonException ignored) {
}
}
switch(response.status()) {
// NOT IMPLEMENTED
case 501:
case // UNSUPPORTED_MEDIA_TYPE
415:
return new MetacatNotSupportedException(message);
case // BAD_REQUEST
400:
return new MetacatBadRequestException(message);
case // Forbidden
403:
return new MetacatUnAuthorizedException(message);
case // NOT_FOUND
404:
return new MetacatNotFoundException(message);
case // CONFLICT
409:
return new MetacatAlreadyExistsException(message);
case // PRECONDITION_FAILED
412:
return new MetacatPreconditionFailedException(message);
case 429:
return new RetryableException(response.status(), message, response.request() == null ? null : response.request().httpMethod(), new MetacatTooManyRequestsException(message), Date.from(Instant.now().plus(1, ChronoUnit.MINUTES)), response.request());
// INTERNAL_SERVER_ERROR
case 500:
case // SERVICE_UNAVAILABLE
503:
return new RetryableException(response.status(), message, response.request() == null ? null : response.request().httpMethod(), new MetacatException(message), null, response.request());
default:
return new MetacatException(message);
}
} catch (final IOException e) {
return super.decode(methodKey, response);
}
}
Aggregations