Search in sources :

Example 1 with MetacatUnAuthorizedException

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);
    }
}
Also used : MetacatTooManyRequestsException(com.netflix.metacat.common.exception.MetacatTooManyRequestsException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) MetacatJsonException(com.netflix.metacat.common.json.MetacatJsonException) MetacatException(com.netflix.metacat.common.exception.MetacatException) IOException(java.io.IOException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) RetryableException(feign.RetryableException) MetacatPreconditionFailedException(com.netflix.metacat.common.exception.MetacatPreconditionFailedException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) MetacatUnAuthorizedException(com.netflix.metacat.common.exception.MetacatUnAuthorizedException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MetacatAlreadyExistsException (com.netflix.metacat.common.exception.MetacatAlreadyExistsException)1 MetacatBadRequestException (com.netflix.metacat.common.exception.MetacatBadRequestException)1 MetacatException (com.netflix.metacat.common.exception.MetacatException)1 MetacatNotFoundException (com.netflix.metacat.common.exception.MetacatNotFoundException)1 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)1 MetacatPreconditionFailedException (com.netflix.metacat.common.exception.MetacatPreconditionFailedException)1 MetacatTooManyRequestsException (com.netflix.metacat.common.exception.MetacatTooManyRequestsException)1 MetacatUnAuthorizedException (com.netflix.metacat.common.exception.MetacatUnAuthorizedException)1 MetacatJsonException (com.netflix.metacat.common.json.MetacatJsonException)1 RetryableException (feign.RetryableException)1 IOException (java.io.IOException)1