public Exception decode()

in metacat-client/src/main/java/com/netflix/metacat/client/module/MetacatErrorDecoder.java [55:99]


    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()) {
                case 501: //NOT IMPLEMENTED
                case 415: //UNSUPPORTED_MEDIA_TYPE
                    return new MetacatNotSupportedException(message);
                case 400: //BAD_REQUEST
                    return new MetacatBadRequestException(message);
                case 403: //Forbidden
                    return new MetacatUnAuthorizedException(message);
                case 404: //NOT_FOUND
                    return new MetacatNotFoundException(message);
                case 409: //CONFLICT
                    return new MetacatAlreadyExistsException(message);
                case 412: // PRECONDITION_FAILED
                    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());
                case 500: //INTERNAL_SERVER_ERROR
                case 503: //SERVICE_UNAVAILABLE
                    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);
        }
    }