use of com.sx4.bot.entities.image.ImageError in project Sx4 by sx4-discord-bot.
the class ImageUtility method getErrorMessage.
public static MessageAction getErrorMessage(TextChannel channel, int status, String fullBody, BiFunction<Document, ImageError, MessageAction> badRequest) {
if (status == 400) {
Document body = Document.parse(fullBody);
int code = body.getEmbedded(List.of("details", "code"), Integer.class);
ImageError error = ImageError.fromCode(code);
if (error != null && error.isUrlError()) {
return channel.sendMessageFormat("That url could not be formed to a valid image %s", Config.get().getFailureEmote());
}
MessageAction messageAction = badRequest == null ? null : badRequest.apply(body, error);
if (messageAction == null) {
return channel.sendMessageEmbeds(ExceptionUtility.getSimpleErrorMessage(String.format("- Code: %d\n- %s", error.getCode(), body.getString("message")), "diff"));
} else {
return messageAction;
}
} else {
return channel.sendMessageEmbeds(ExceptionUtility.getSimpleErrorMessage(String.format("- Status: %d\n- %s", status, fullBody), "diff"));
}
}
Aggregations