fix RYD voting

This commit is contained in:
caneleex 2022-01-26 14:43:52 +01:00
parent 48c268b0bc
commit 6bac0407bb
2 changed files with 11 additions and 5 deletions

View File

@ -21,20 +21,26 @@ public class Requester {
} }
public static String parseJson(HttpURLConnection connection) throws IOException { public static String parseJson(HttpURLConnection connection) throws IOException {
return parseJson(connection.getInputStream()); return parseJson(connection.getInputStream(), false);
} }
public static String parseJson(InputStream inputStream) throws IOException { public static String parseJson(InputStream inputStream, boolean isError) throws IOException {
StringBuilder jsonBuilder = new StringBuilder(); StringBuilder jsonBuilder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
jsonBuilder.append(line).append("\n"); jsonBuilder.append(line);
if (isError)
jsonBuilder.append("\n");
} }
inputStream.close(); inputStream.close();
return jsonBuilder.toString(); return jsonBuilder.toString();
} }
public static String parseErrorJson(HttpURLConnection connection) throws IOException {
return parseJson(connection.getErrorStream(), true);
}
public static JSONObject getJSONObject(HttpURLConnection connection) throws Exception { public static JSONObject getJSONObject(HttpURLConnection connection) throws Exception {
return new JSONObject(parseJsonAndDisconnect(connection)); return new JSONObject(parseJsonAndDisconnect(connection));
} }

View File

@ -91,7 +91,7 @@ public class SBRequester {
SponsorBlockUtils.messageToToast = str("submit_failed_duplicate"); SponsorBlockUtils.messageToToast = str("submit_failed_duplicate");
break; break;
case 403: case 403:
SponsorBlockUtils.messageToToast = str("submit_failed_forbidden", Requester.parseJson(connection.getErrorStream())); SponsorBlockUtils.messageToToast = str("submit_failed_forbidden", Requester.parseErrorJson(connection));
break; break;
case 429: case 429:
SponsorBlockUtils.messageToToast = str("submit_failed_rate_limit"); SponsorBlockUtils.messageToToast = str("submit_failed_rate_limit");
@ -137,7 +137,7 @@ public class SBRequester {
SponsorBlockUtils.messageToToast = str("vote_succeeded"); SponsorBlockUtils.messageToToast = str("vote_succeeded");
break; break;
case 403: case 403:
SponsorBlockUtils.messageToToast = str("vote_failed_forbidden", Requester.parseJson(connection.getErrorStream())); SponsorBlockUtils.messageToToast = str("vote_failed_forbidden", Requester.parseErrorJson(connection));
break; break;
default: default:
SponsorBlockUtils.messageToToast = str("vote_failed_unknown_error", responseCode, connection.getResponseMessage()); SponsorBlockUtils.messageToToast = str("vote_failed_unknown_error", responseCode, connection.getResponseMessage());