Skip to content

Commit dd29c3a

Browse files
committed
fix: JSON parse error due to null response when page is not ready
1 parent bf7747b commit dd29c3a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/src/main/java/tk/therealsuji/vtopchennai/services/VTOPService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ public void onPageFinished(WebView view, String url) {
192192
"const response = {" +
193193
" page_type: 'LANDING'" +
194194
"};" +
195-
"if ($('input[id=\"authorizedIDX\"]').length === 1) {" +
195+
"if (document.body === null) {" +
196+
" response.page_type = 'BODY_NOT_READY';" +
197+
"} else if ($('input[id=\"authorizedIDX\"]').length === 1) {" +
196198
" response.page_type = 'HOME';" +
197-
"} if ($('form[id=\"vtopLoginForm\"]').length === 1) {" +
199+
"} else if ($('form[id=\"vtopLoginForm\"]').length === 1) {" +
198200
" response.page_type = 'LOGIN';" +
199201
"}" +
200202
"return response;" +
@@ -232,11 +234,13 @@ public void onPageFinished(WebView view, String url) {
232234
getSemesters();
233235
pageState = PageState.HOME;
234236
break;
237+
case "BODY_NOT_READY":
238+
break;
235239
default:
236240
throw new Error("Unknown page exception.");
237241
}
238242
} catch (JSONException e) {
239-
Toast.makeText(VTOPService.this, "Error:" + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
243+
Toast.makeText(VTOPService.this, "Error: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
240244
}
241245
});
242246
}

0 commit comments

Comments
 (0)