From 70bbbc3c2002c55866db74d8121e94ef848c5cfd Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:55:33 +1100 Subject: Fixed rare farming weight API errors. #1014 --- src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt index 0f561fdff..33da6ed38 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt @@ -116,7 +116,6 @@ object APIUtil { } val message = "POST request to '$urlString' returned status ${status.statusCode}" - println(message) ChatUtils.error("SkyHanni ran into an error. Status: ${status.statusCode}") return ApiResponse(false, message, JsonObject()) } @@ -134,8 +133,10 @@ object APIUtil { } private fun readResponse(entity: HttpEntity): JsonObject { - val retSrc = EntityUtils.toString(entity) - return parser.parse(retSrc) as JsonObject + val retSrc = EntityUtils.toString(entity) ?: return JsonObject() + val parsed = parser.parse(retSrc) + if (parsed.isJsonNull) return JsonObject() + return parsed as JsonObject } fun postJSONIsSuccessful(url: String, body: String, silentError: Boolean = false): Boolean { @@ -145,12 +146,12 @@ object APIUtil { return true } - println(response.message) ErrorManager.logErrorStateWithData( "An error occurred during the API request", "unsuccessful API response", "url" to url, "body" to body, + "message" to response.message, "response" to response, ) -- cgit