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

uk.co.mruoc.camunda.client.ResponseConverter Maven / Gradle / Ivy

There is a newer version: 0.1.29
Show newest version
package uk.co.mruoc.camunda.client;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.co.mruoc.json.JsonConverter;

import java.net.http.HttpResponse;

@Slf4j
@RequiredArgsConstructor
public class ResponseConverter {

    private final JsonConverter jsonConverter;

    public  T toTypeOrThrowError(HttpResponse response, Class type) {
        String body = response.body();
        if (isSuccessful(response)) {
            log.info(body);
            return jsonConverter.toObject(body, type);
        }
        throw new CamundaClientException(body);
    }

    private boolean isSuccessful(HttpResponse response) {
        var status = response.statusCode();
        return status >= 200 && status <= 299;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy