private IOException newException()

in src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java [298:321]


    private IOException newException(CloseableHttpResponse response, InputStreamReader reader) {
        
        StringBuilder message = new StringBuilder();
        message.append("Status line : ").append(response.getStatusLine());
        
        try {
            Gson gson = new Gson();
            ErrorResponse errors = gson.fromJson(reader, ErrorResponse.class);
            if ( errors != null ) {
                if ( !errors.getErrorMessages().isEmpty() )
                    message.append(". Error messages: ")
                        .append(errors.getErrorMessages());
                
                if ( !errors.getErrors().isEmpty() )
                    errors.getErrors().forEach((key, value) -> message.append(". Error for ").append(key).append(" : ").append(value));
            }
        } catch ( JsonIOException | JsonSyntaxException e) {
            message.append(". Failed parsing response as JSON ( ")
                .append(e.getMessage())
                .append(" )");
        }
        
        return new IOException(message.toString());
    }