
uk.co.mruoc.camunda.client.ResponseConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camunda-rest-client Show documentation
Show all versions of camunda-rest-client Show documentation
Template repo to speed up creating new library projects
The newest version!
package uk.co.mruoc.camunda.client;
import java.net.http.HttpResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.co.mruoc.json.JsonConverter;
@Slf4j
@RequiredArgsConstructor
public class ResponseConverter {
private final JsonConverter jsonConverter;
public void throwErrorIfRequired(HttpResponse response) {
log(response);
if (!isSuccessful(response)) {
throw new CamundaClientException(response.body());
}
}
public T toTypeOrThrowError(HttpResponse response, Class type) {
log(response);
String body = response.body();
if (isSuccessful(response)) {
return jsonConverter.toObject(body, type);
}
throw new CamundaClientException(body);
}
private void log(HttpResponse response) {
log.info("response status: {} body: {}", response.statusCode(), response.body());
}
private boolean isSuccessful(HttpResponse response) {
var status = response.statusCode();
log.info("status: " + status);
return status >= 200 && status <= 299;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy