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

com.manywho.sdk.api.run.ApiProblemException Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.manywho.sdk.api.run;

import com.google.common.collect.HashMultimap;

public class ApiProblemException extends Exception {
    private String uri;
    private int statusCode;
    private String responseBody;
    private HashMultimap responseHeaders;
    private String message;

    public ApiProblemException(String uri, int statusCode, String responseBody, HashMultimap responseHeaders, String message) {
        this.uri = uri;
        this.statusCode = statusCode;
        this.responseBody = responseBody;
        this.message = message;
        this.responseHeaders = stripSecureHeaders(responseHeaders);
    }

    public ApiProblemException(String uri, int statusCode, String responseBody, String message) {
        this(uri, statusCode, responseBody, null, message);
    }

    public ApiProblemException(String uri, int statusCode, String message) {
        this(uri, statusCode, null, message);
    }

    public String getUri() {
        return uri;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public String getResponseBody() {
        return responseBody;
    }

    public HashMultimap getResponseHeaders() {
        return responseHeaders;
    }

    @Override
    public String getMessage() {
        return message;
    }

    private HashMultimap stripSecureHeaders(HashMultimap headers) {
        if (headers != null && !headers.isEmpty()) {
            for (String secureHeader : new String[]{"Authorization", "X-Forwarded-For"}) {
                if (headers.containsKey(secureHeader)) {
                    headers.removeAll(secureHeader);
                }
            }
        }

        return headers;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy