core/src/main/java/net/typedrest/AbstractEndpoint.java
protected void handleErrors(HttpResponse response, Request request)
            throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() <= 299) {
            return;
        }

        String message = request + " responded with " + statusLine.getStatusCode() + " " + statusLine.getReasonPhrase();

        HttpEntity entity = response.getEntity();
        String body;
        if (entity == null) {
            body = null;
        } else {
            body = EntityUtils.toString(entity);
            Header contentType = entity.getContentType();
            if ((contentType != null) && contentType.getValue().startsWith("application/json")) {
                try {
                    JsonNode messageNode = serializer.readTree(body).get("message");
                    if (messageNode != null) {
                        message = messageNode.asText();
                    }
                } catch (JsonProcessingException ex) {
                }
            }
        }

        Exception inner = (body == null) ? null : new HttpException(body);
        switch (statusLine.getStatusCode()) {
            case HttpStatus.SC_BAD_REQUEST:
                throw new IllegalArgumentException(message, inner);
            case HttpStatus.SC_UNAUTHORIZED:
                //throw new InvalidCredentialException(message);
                throw new IllegalAccessException(message);
            case HttpStatus.SC_FORBIDDEN:
                throw new IllegalAccessException(message);
            case HttpStatus.SC_NOT_FOUND:
            case HttpStatus.SC_GONE:
                throw new FileNotFoundException(message);
            case HttpStatus.SC_CONFLICT:
                throw new IllegalStateException(message, inner);
            case HttpStatus.SC_PRECONDITION_FAILED:
                //throw new VersionNotFoundException(message, inner);
                throw new IllegalStateException(message, inner);
            case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
                //throw new IndexOutOfBoundsException(message);
                throw new IllegalStateException(message, inner);
            case HttpStatus.SC_REQUEST_TIMEOUT:
            //throw new TimeoutException(message);
            default:
                throw new RuntimeException(message, inner);
        }
    }
protected void handleErrors(HttpResponse response, Request request)
            throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() <= 299) {
            return;
        }

        String message = request + " responded with " + statusLine.getStatusCode() + " " + statusLine.getReasonPhrase();

        HttpEntity entity = response.getEntity();
        String body;
        if (entity == null) {
            body = null;
        } else {
            body = EntityUtils.toString(entity);
            Header contentType = entity.getContentType();
            if ((contentType != null) && contentType.getValue().startsWith("application/json")) {
                try {
                    JsonNode messageNode = serializer.readTree(body).get("message");
                    if (messageNode != null) {
                        message = messageNode.asText();
                    }
                } catch (JsonProcessingException ex) {
                }
            }
        }

        Exception inner = (body == null) ? null : new HttpException(body);
        switch (statusLine.getStatusCode()) {
            case HttpStatus.SC_BAD_REQUEST:
                throw new IllegalArgumentException(message, inner);
            case HttpStatus.SC_UNAUTHORIZED:
                //throw new InvalidCredentialException(message);
                throw new IllegalAccessException(message);
            case HttpStatus.SC_FORBIDDEN:
                throw new IllegalAccessException(message);
            case HttpStatus.SC_NOT_FOUND:
            case HttpStatus.SC_GONE:
                throw new FileNotFoundException(message);
            case HttpStatus.SC_CONFLICT:
                throw new IllegalStateException(message, inner);
            case HttpStatus.SC_PRECONDITION_FAILED:
                //throw new VersionNotFoundException(message, inner);
                throw new IllegalStateException(message, inner);
            case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
                //throw new IndexOutOfBoundsException(message);
                throw new IllegalStateException(message, inner);
            case HttpStatus.SC_REQUEST_TIMEOUT:
            //throw new TimeoutException(message);
            default:
                throw new RuntimeException(message, inner);
        }
    }
protected void handleErrors ( HttpResponse response , Request request ) throws IOException , IllegalArgumentException , IllegalAccessException , FileNotFoundException , IllegalStateException { StatusLine statusLine = response . getStatusLine ( ) ; if ( statusLine . getStatusCode ( ) <= 299 ) { return ; } String message = request + " responded with " + statusLine . getStatusCode ( ) + " " + statusLine . getReasonPhrase ( ) ; HttpEntity entity = response . getEntity ( ) ; String body ; if ( entity == null ) { body = null ; } else { body = EntityUtils . toString ( entity ) ; Header contentType = entity . getContentType ( ) ; if ( ( contentType != null ) && contentType . getValue ( ) . startsWith ( "application/json" ) ) { try { JsonNode messageNode = serializer . readTree ( body ) . get ( "message" ) ; if ( messageNode != null ) { message = messageNode . asText ( ) ; } } catch ( JsonProcessingException ex ) { } } } Exception inner = ( body == null ) ? null : new HttpException ( body ) ; switch ( statusLine . getStatusCode ( ) ) { case HttpStatus . SC_BAD_REQUEST : throw new IllegalArgumentException ( message , inner ) ; case HttpStatus . SC_UNAUTHORIZED : //throw new InvalidCredentialException(message); throw new IllegalAccessException ( message ) ; case HttpStatus . SC_FORBIDDEN : throw new IllegalAccessException ( message ) ; case HttpStatus . SC_NOT_FOUND : case HttpStatus . SC_GONE : throw new FileNotFoundException ( message ) ; case HttpStatus . SC_CONFLICT : throw new IllegalStateException ( message , inner ) ; case HttpStatus . SC_PRECONDITION_FAILED : //throw new VersionNotFoundException(message, inner); throw new IllegalStateException ( message , inner ) ; case HttpStatus . SC_REQUESTED_RANGE_NOT_SATISFIABLE : //throw new IndexOutOfBoundsException(message); throw new IllegalStateException ( message , inner ) ; case HttpStatus . SC_REQUEST_TIMEOUT : //throw new TimeoutException(message); default : throw new RuntimeException ( message , inner ) ; } }
Wraps HTTP status codes in appropriate {@link Exception} types.

@param response The response to check for errors.
@param request The original request the reponse is for.

@throws IOException Network communication failed.
@throws IllegalArgumentException {@link HttpStatus#SC_BAD_REQUEST}
@throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or
{@link HttpStatus#SC_FORBIDDEN}
@throws FileNotFoundException {@link HttpStatus#SC_NOT_FOUND} or
{@link HttpStatus#SC_GONE}
@throws IllegalStateException
{@link HttpStatus#SC_CONFLICT}, {@link HttpStatus#SC_PRECONDITION_FAILED}
or {@link HttpStatus#SC_REQUESTED_RANGE_NOT_SATISFIABLE}
@throws RuntimeException Other non-success status code.
Wraps HTTP status codes in appropriate { @link Exception } types .