Skip to content

Commit afce3f5

Browse files
committed
Handle no responseJSON coming back from POSTs/xhrs
Signed-off-by: Rob Pilling <[email protected]>
1 parent 0a962ba commit afce3f5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

scripts/js/login.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ function wrongPassword(isError = false, isSuccess = false, data = null) {
3030
$("#error-message").text("");
3131
$("#error-hint").hide();
3232
$("#error-hint").text("");
33-
if (data !== null && "error" in data.responseJSON && "message" in data.responseJSON.error) {
33+
if (
34+
data !== null &&
35+
"responseJSON" in data &&
36+
"error" in data.responseJSON &&
37+
"message" in data.responseJSON.error
38+
) {
3439
// This is an error, highlight both the password and the TOTP field
3540
isErrorResponse = true;
3641
// Check if the error is caused by an invalid TOTP token
@@ -168,13 +173,15 @@ $(function () {
168173
if (data.session.valid === true) redirect();
169174
})
170175
.fail(function (xhr) {
171-
const session = xhr.responseJSON.session;
172-
// If TOPT is enabled, show the input field and add the required attribute
173-
if (session.totp === true) {
174-
$("#totp_input").removeClass("hidden");
175-
$("#totp").attr("required", "required");
176-
$("#totp-forgotten-title").removeClass("hidden");
177-
$("#totp-forgotten-body").removeClass("hidden");
176+
if ("responseJSON" in xhr) {
177+
const session = xhr.responseJSON.session;
178+
// If TOPT is enabled, show the input field and add the required attribute
179+
if (session.totp === true) {
180+
$("#totp_input").removeClass("hidden");
181+
$("#totp").attr("required", "required");
182+
$("#totp-forgotten-title").removeClass("hidden");
183+
$("#totp-forgotten-body").removeClass("hidden");
184+
}
178185
}
179186
});
180187

0 commit comments

Comments
 (0)