All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.trolley.Exceptions.InvalidServerConnectionException Maven / Gradle / Ivy

The newest version!
package com.trolley.Exceptions;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class InvalidServerConnectionException extends Exception
{
    private JsonNode errorResponse = null;

    /**
     * Get the JSON object representing the error response.
     * The returned object could be null if the error response string couldn't be parsed as JSON.
     * @return JsonNode errorResponse
     */
    public JsonNode getErrorResponse(){
        return errorResponse;
    }

    private void setErrorResponse(JsonNode errorJson){
        this.errorResponse = errorJson;
    }

    public InvalidServerConnectionException() {
    }
    
    public InvalidServerConnectionException(final String message) {
        super(message);
        ObjectMapper mapper = new ObjectMapper();
        try {
            JsonNode errorJson = mapper.readTree(message);
            this.setErrorResponse(errorJson);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy