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

io.github.jpmorganchase.fusion.api.tools.ResponseChecker Maven / Gradle / Ivy

There is a newer version: 0.0.14
Show newest version
package io.github.jpmorganchase.fusion.api.tools;

import io.github.jpmorganchase.fusion.api.exception.APICallException;
import io.github.jpmorganchase.fusion.http.HttpResponse;

public class ResponseChecker {

    /**
     * @param response to be verified
     * @param  type expected in the body of the response
     * @throws APICallException indicating a failure to communicate with Fusion API
     */
    public static  void checkResponseStatus(HttpResponse response) throws APICallException {
        if (response.isError()) {
            throw new APICallException(response.getStatusCode(), extractErrorDetailFromBody(response));
        }
    }

    private static  String extractErrorDetailFromBody(final HttpResponse response) {
        if (null != response.getBody()) {
            return RegexBasedErrorParser.get(response.getBody().toString());
        }
        return RegexBasedErrorParser.UNKNOWN;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy