Browse code

fix timeout issue

Louis authored on05/05/2025 18:36:16
Showing2 changed files
1 1
Binary files a/build/synocam_home_switch.pbw and b/build/synocam_home_switch.pbw differ
... ...
@@ -156,35 +156,39 @@ function authenticate(action_callback) {
156 156
         }
157 157
         var method = "GET";
158 158
         onload_function = function (xhr) {
159
-            response = JSON.parse(xhr.responseText);
160
-            if (response.success == true) {
161
-                sid = response.data.sid;
162
-                console.log('------Authentication succeeded');
163
-                if (sid != "") {
164
-                    message = "Authenticated";
165
-                    send_message_to_watch(message)
166
-                    home_mode_handler(action_callback);
159
+            console.log(JSON.stringify(xhr));
160
+            if (xhr.status == 0){
161
+                console.log('------Authentication failed because of request timed out');
162
+                message = "Time out";
163
+                send_message_to_watch(message)
164
+            } else {
165
+                response = JSON.parse(xhr.responseText);
166
+                if (response.success == true) {
167
+                    sid = response.data.sid;
168
+                    console.log('------Authentication succeeded');
169
+                    if (sid != "") {
170
+                        message = "Authenticated";
171
+                        send_message_to_watch(message)
172
+                        home_mode_handler(action_callback);
173
+                    } else {
174
+                        console.log('------Unexpected error : authentication is OK but no SID retrieved');
175
+                        message = "Auth error, no SID";
176
+                        send_message_to_watch(message)
177
+                    }
167 178
                 } else {
168
-                    console.log('------Unexpected error : authentication is OK but no SID retrieved');
169
-                    message = "Auth error, no SID";
179
+                    console.log('------Authentication failed : ' + JSON.stringify(response));
180
+                    if (response.error.code == 400) {
181
+                        console.log('------Authentication failed because of wrong creds');
182
+                        message = "Authentication failed, check your credentials";
183
+                    } else if (response.error.code == 404) {
184
+                        console.log('------Authentication failed because of wrong TOTP');
185
+                        message = "Authentication failed, check your TOTP seed";
186
+                    } else if (response.error.code == 407) {
187
+                        console.log('------Authentication failed because of IP Blocked');
188
+                        message = "Authentication failed, IP is blocked";
189
+                    }
170 190
                     send_message_to_watch(message)
171 191
                 }
172
-            } else {
173
-                console.log('------Authentication failed : ' + JSON.stringify(response));
174
-                if (response.error.code == 400) {
175
-                    console.log('------Authentication failed because of wrong creds');
176
-                    message = "Authentication failed, check your credentials";
177
-                } else if (response.error.code == 404) {
178
-                    console.log('------Authentication failed because of wrong TOTP');
179
-                    message = "Authentication failed, check your TOTP seed";
180
-                } else if (response.error.code == 407) {
181
-                    console.log('------Authentication failed because of IP Blocked');
182
-                    message = "Authentication failed, IP is blocked";
183
-                }else if (xhr.status == 0){
184
-                    console.log('------Authentication failed because of request timed out');
185
-                    message = "Time out";
186
-                }
187
-                send_message_to_watch(message)
188 192
             }
189 193
         };        
190 194
         send_message_to_watch("Authenticating....");