mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Change] HttpRequestException 统一接口异常, 调整类所在包路径;
This commit is contained in:
parent
91e065f657
commit
c64320ad78
@ -8,6 +8,7 @@ import net.lamgc.cgj.bot.BotCode;
|
||||
import net.lamgc.cgj.bot.BotCommandProcess;
|
||||
import net.lamgc.cgj.bot.SettingProperties;
|
||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||
import net.lamgc.cgj.exception.HttpRequestException;
|
||||
import net.lamgc.cgj.pixiv.PixivDownload;
|
||||
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||
import net.lamgc.cgj.pixiv.PixivURL;
|
||||
@ -446,7 +447,7 @@ public final class CacheStoreCentral {
|
||||
|
||||
if (jsonObject.get("error").getAsBoolean()) {
|
||||
log.error("接口请求错误, 错误信息: {}", jsonObject.get("message").getAsString());
|
||||
throw new IOException("Interface Request Error: " + jsonObject.get("message").getAsString());
|
||||
throw new HttpRequestException(response.getStatusLine(), responseBody);
|
||||
}
|
||||
|
||||
long expire = 7200 * 1000;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lamgc.cgj.bot.cache;
|
||||
|
||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||
import net.lamgc.cgj.bot.cache.exception.HttpRequestException;
|
||||
import net.lamgc.cgj.exception.HttpRequestException;
|
||||
import net.lamgc.cgj.pixiv.PixivURL;
|
||||
import net.lamgc.cgj.util.URLs;
|
||||
import net.lamgc.utils.event.EventHandler;
|
||||
|
@ -7,7 +7,7 @@ import com.google.gson.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.lamgc.cgj.bot.cache.exception.HttpRequestException;
|
||||
import net.lamgc.cgj.exception.HttpRequestException;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.lamgc.cgj.bot.cache.exception;
|
||||
package net.lamgc.cgj.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
@ -6,6 +6,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import net.lamgc.cgj.exception.HttpRequestException;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
@ -326,7 +327,7 @@ public class PixivDownload {
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
log.trace("ResponseBody: {}", responseBody);
|
||||
if(response.getStatusLine().getStatusCode() != 200) {
|
||||
throw new IOException("Http Response Error: '" + response.getStatusLine() + "', ResponseBody: '" + responseBody + '\'');
|
||||
throw new HttpRequestException(response.getStatusLine(), responseBody);
|
||||
}
|
||||
|
||||
JsonObject resultObject = gson.fromJson(responseBody, JsonObject.class);
|
||||
@ -353,7 +354,7 @@ public class PixivDownload {
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
|
||||
if(response.getStatusLine().getStatusCode() != 200) {
|
||||
throw new IOException("Http响应码非200: " + response.getStatusLine());
|
||||
throw new HttpRequestException(response);
|
||||
}
|
||||
|
||||
Document document = Jsoup.parse(EntityUtils.toString(response.getEntity()));
|
||||
@ -401,7 +402,7 @@ public class PixivDownload {
|
||||
if(resultObject.get("error").getAsBoolean()) {
|
||||
String message = resultObject.get("message").getAsString();
|
||||
log.warn("作品页面接口请求错误, 错误信息: {}", message);
|
||||
throw new IOException(message);
|
||||
throw new HttpRequestException(response);
|
||||
}
|
||||
|
||||
JsonArray linkArray = resultObject.getAsJsonArray("body");
|
||||
@ -554,7 +555,7 @@ public class PixivDownload {
|
||||
JsonObject responseObj = new Gson().fromJson(responseStr, JsonObject.class);
|
||||
|
||||
if(responseObj.get("error").getAsBoolean()) {
|
||||
throw new IOException(responseObj.get("message").getAsString());
|
||||
throw new HttpRequestException(response.getStatusLine(), responseStr);
|
||||
}
|
||||
|
||||
JsonArray illustsArray = responseObj.getAsJsonObject("body").getAsJsonArray("illusts");
|
||||
|
@ -7,6 +7,7 @@ import com.squareup.gifencoder.GifEncoder;
|
||||
import com.squareup.gifencoder.Image;
|
||||
import com.squareup.gifencoder.ImageOptions;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import net.lamgc.cgj.exception.HttpRequestException;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
@ -51,7 +52,7 @@ public final class PixivUgoiraBuilder {
|
||||
if(resultObject.get("error").getAsBoolean()) {
|
||||
String message = resultObject.get("message").getAsString();
|
||||
log.error("获取动图元数据失败!(接口报错: {})", message);
|
||||
throw new IOException(message);
|
||||
throw new HttpRequestException(response.getStatusLine(), bodyStr);
|
||||
} else if(!resultObject.has("body")) {
|
||||
String message = "接口返回数据不存在body属性, 可能接口发生改变!";
|
||||
log.error(message);
|
||||
@ -181,7 +182,7 @@ public final class PixivUgoiraBuilder {
|
||||
if(resultObject.get("error").getAsBoolean()) {
|
||||
String message = resultObject.get("message").getAsString();
|
||||
log.error("接口返回错误: {}", message);
|
||||
throw new IOException(message);
|
||||
throw new HttpRequestException(response.getStatusLine(), responseBody);
|
||||
}
|
||||
|
||||
JsonArray illustsArray = resultObject.getAsJsonObject("body").getAsJsonArray("illusts");
|
||||
|
Loading…
Reference in New Issue
Block a user