io.github.robothy.sdwebui.sdk.utils.SdWebuiResponseUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdwebui-java-sdk Show documentation
Show all versions of sdwebui-java-sdk Show documentation
Stable Diffusion Web UI Java SDK
The newest version!
package io.github.robothy.sdwebui.sdk.utils;
import io.github.robothy.sdwebui.sdk.exceptions.SdWebuiBadRequestException;
import io.github.robothy.sdwebui.sdk.exceptions.SdWebuiServerValidationException;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpStatus;
public class SdWebuiResponseUtils {
public static void checkResponseStatus(ClassicHttpResponse response) {
if (response.getCode() == HttpStatus.SC_OK) {
return;
}
try {
if (response.getCode() == HttpStatus.SC_UNPROCESSABLE_ENTITY) {
JsonUtils.fromJson(response.getEntity().getContent(), SdWebuiServerValidationException.class);
}
throw JsonUtils.fromJson(response.getEntity().getContent(), SdWebuiBadRequestException.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static T parseResponse(ClassicHttpResponse response, Class clazz) {
checkResponseStatus(response);
try {
return JsonUtils.fromJson(response.getEntity().getContent(), clazz);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}