Skip to content

Commit

Permalink
Log body when encountering request error
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Feb 21, 2025
1 parent 7bbda1c commit 8d5086d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import net.neoforged.waifu.Main;
import net.neoforged.waifu.meta.ModFileInfo;
import net.neoforged.waifu.platform.ModPlatform;
import net.neoforged.waifu.platform.PlatformMod;
Expand Down Expand Up @@ -292,7 +293,13 @@ private <T> T send(HttpRequest.Builder builder, TypeToken<T> type) {
}
}

return Utils.GSON.fromJson(res.body(), type);
try {
return Utils.GSON.fromJson(res.body(), type);
} catch (IllegalStateException ex) {
Main.LOGGER.error("Failed to decode request body from {} ({}): {}", res.uri(), res, res.body());
throw new IllegalStateException("Failed to decode body of request to " + builder.build().uri() + " (first 100 chars) \"" +
res.body().substring(0, Math.min(100, res.body().length())) + "\": " + ex.getMessage(), ex);
}
}

private static String loader(ModLoader loader) {
Expand Down

0 comments on commit 8d5086d

Please # to comment.