Search in sources :

Example 1 with RetryableException

use of feign.RetryableException 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 = METACAT_JSON.parseJsonObject(message);
                message = body.path("error").asText();
            } catch (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 //NOT_FOUND
            404:
                return new MetacatNotFoundException(message);
            case //CONFLICT
            409:
                return new MetacatAlreadyExistsException(message);
            //INTERNAL_SERVER_ERROR
            case 500:
            case //SERVICE_UNAVAILABLE
            503:
                return new RetryableException(message, null);
            default:
                return new MetacatException(message, javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, null);
        }
    } catch (final IOException e) {
        return super.decode(methodKey, response);
    }
}
Also used : MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) RetryableException(feign.RetryableException) 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) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) 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 MetacatJsonException (com.netflix.metacat.common.json.MetacatJsonException)1 RetryableException (feign.RetryableException)1 IOException (java.io.IOException)1