Search in sources :

Example 16 with ApiException

use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.

the class RequestUtils method assertResponse.

public static void assertResponse(Response resp) throws ApiException, IOException {
    int code = resp.code();
    if (code < 200 || code >= 400) {
        try (ResponseBody body = resp.body()) {
            if (isJson(resp)) {
                Object details = objectMapper.readValue(body.byteStream(), Object.class);
                String msg = extractMessage(details);
                throw new ApiException(code, msg);
            } else {
                if (code == 401) {
                    throw new ApiException(code, "Request error: " + code + ", please verify the credentials used");
                } else {
                    throw new ApiException(code, "Request error: " + code);
                }
            }
        }
    }
}
Also used : ResponseBody(com.squareup.okhttp.ResponseBody) ApiException(com.walmartlabs.concord.ApiException)

Aggregations

ApiException (com.walmartlabs.concord.ApiException)16 Test (org.junit.jupiter.api.Test)8 HashMap (java.util.HashMap)5 ProjectEntry (com.walmartlabs.concord.client.ProjectEntry)3 ProjectsApi (com.walmartlabs.concord.client.ProjectsApi)3 File (java.io.File)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)2 Path (java.nio.file.Path)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ResponseBody (com.squareup.okhttp.ResponseBody)1 ApiClient (com.walmartlabs.concord.ApiClient)1 CreateUserRequest (com.walmartlabs.concord.client.CreateUserRequest)1 ProcessApi (com.walmartlabs.concord.client.ProcessApi)1 StartProcessResponse (com.walmartlabs.concord.client.StartProcessResponse)1 UsersApi (com.walmartlabs.concord.client.UsersApi)1 StepCommand (com.walmartlabs.concord.runtime.v2.runner.vm.StepCommand)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Git (org.eclipse.jgit.api.Git)1