@@ -25,31 +25,34 @@ function redirect() {
2525 globalThis . location . replace ( target ) ;
2626}
2727
28+ function showErrorMessage ( errorMessage ) {
29+ $ ( "#error-message" ) . text ( errorMessage ) ;
30+ $ ( "#error-label" ) . show ( ) ;
31+ }
32+
2833function wrongPassword ( isError = false , isSuccess = false , data = null ) {
2934 if ( isError ) {
3035 let isErrorResponse = false ;
3136 let isInvalidTOTP = false ;
32-
37+ let errorMessage = "Wrong password!" ;
3338 // Reset hint and error message
3439 $ ( "#error-message" ) . text ( "" ) ;
3540 $ ( "#error-hint" ) . hide ( ) ;
3641 $ ( "#error-hint" ) . text ( "" ) ;
37- if ( data !== null && "error" in data . responseJSON && "message" in data . responseJSON . error ) {
42+
43+ if ( "error" in data . responseJSON && "message" in data . responseJSON . error ) {
3844 // This is an error, highlight both the password and the TOTP field
3945 isErrorResponse = true ;
4046 // Check if the error is caused by an invalid TOTP token
4147 isInvalidTOTP = data . responseJSON . error . message === "Invalid 2FA token" ;
42- $ ( "#error-message" ) . text ( data . responseJSON . error . message ) ;
48+ errorMessage = data . responseJSON . error . message ;
4349 if ( "hint" in data . responseJSON . error && data . responseJSON . error . hint !== null ) {
4450 $ ( "#error-hint" ) . text ( data . responseJSON . error . hint ) ;
4551 $ ( "#error-hint" ) . show ( ) ;
4652 }
47- } else {
48- $ ( "#error-message" ) . text ( "Wrong password!" ) ;
4953 }
5054
51- $ ( "#error-label" ) . show ( ) ;
52-
55+ showErrorMessage ( errorMessage ) ;
5356 // Always highlight the TOTP field on error
5457 if ( isErrorResponse ) $ ( "#totp_input" ) . addClass ( "has-error" ) ;
5558
@@ -105,7 +108,12 @@ function doLogin(password) {
105108 redirect ( ) ;
106109 } )
107110 . fail ( data => {
108- wrongPassword ( true , false , data ) ;
111+ if ( ! data || ! data . responseJSON ) {
112+ showErrorMessage ( "Server unreachable!" ) ;
113+ } else {
114+ wrongPassword ( true , false , data ) ;
115+ }
116+
109117 NProgress . done ( ) ;
110118 utils . enableAll ( ) ;
111119 } ) ;
0 commit comments