diff app/override/RestProxy.js @ 618:fb89f61ab272 openid

Improve error handling on authentication loss.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 13 Mar 2015 17:17:09 +0100
parents 7fd9350eacf9
children 44d7822d0d55
line wrap: on
line diff
--- a/app/override/RestProxy.js	Fri Mar 13 15:00:55 2015 +0100
+++ b/app/override/RestProxy.js	Fri Mar 13 17:17:09 2015 +0100
@@ -15,20 +15,31 @@
     },
 
     processResponse: function (success, operation, request, response, callback, scope) {
-        if (!success && response.status == 401) {
+        /* Check if we were authenticated at one point (Lada.openIDParams) and
+         * if the response means that we lost that authentcation */
+        if (Lada.openIDParams && !success && response.status == 401) {
             var json = Ext.decode(response.responseText);
             if (json) {
-                if (json.message == "699") {
+                if (json.message === "699" || json.message === "698") {
                     /* This is the unauthorized message with the authentication
                      * redirect in the data */
 
                     /* We decided to handle this with a redirect to the identity
                      * provider. In which case we have no other option then to
                      * handle it here with relaunch. */
-                    Lada.launch(); // Data loss!
+                    Ext.MessageBox.confirm('Erneutes Login erforderlich',
+                        'Der Server konnte die Anfrage nicht authentifizieren.<br/>'+
+                        'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' +
+                        'Alle ungesicherten Daten gehen dabei verloren.<br/>' +
+                        'Soll die Anwendung jetzt neu geladen werden?', this.reload);
                 }
             }
         }
         this.callParent(arguments);
+    },
+    reload: function(btn) {
+        if (btn === 'yes') {
+            location.reload();
+        }
     }
 });

http://lada.wald.intevation.org