changeset 812:188a9faf96e0

Added Errorhandling for AJAX-Requests, especially Authentication Issues.
author Dustin Demuth <dustin@intevation.de>
date Wed, 27 May 2015 16:59:23 +0200
parents 5cdfe0ff1df3
children ee8cce4b4522
files app/controller/FilterResult.js app/view/window/GenProbenFromMessprogramm.js
diffstat 2 files changed, 63 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/FilterResult.js	Wed May 27 16:04:59 2015 +0200
+++ b/app/controller/FilterResult.js	Wed May 27 16:59:23 2015 +0200
@@ -136,11 +136,46 @@
                 var blob = new Blob([content],{type: 'text/plain'});
                 saveAs(blob, 'export.laf');
             },
-            failure: function() {
-                // TODO handle Errors correctly, especially AuthenticationTimeouts
-                Ext.Msg.create(i18n.getMsg('err.msg.generic.title'),
+            failure: function(response) {
+                var json = Ext.JSON.decode(response.responseText);
+                if (json) {
+                    if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
+                        formPanel.setMessages(json.errors, json.warnings);
+                    }
+                    // TODO Move this handling of 699 and 698 to a more central place!
+                    // TODO i18n
+                    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. */
+                        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); //TODO Scope?
+                    }
+                    else if(json.message){
+                        Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
+                            +' #'+json.message,
+                            Lada.getApplication().bundle.getMsg(json.message));
+                    } else {
+                        Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
+                            i18n.getMsg('err.msg.laf.filecreatefailed'));
+                    }
+                } else {
+                    Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
                     i18n.getMsg('err.msg.laf.filecreatefailed'));
+                }
             }
         });
+    },
+
+    reload: function(btn) {
+        if (btn === 'yes') {
+            location.reload();
+        }
     }
 });
--- a/app/view/window/GenProbenFromMessprogramm.js	Wed May 27 16:04:59 2015 +0200
+++ b/app/view/window/GenProbenFromMessprogramm.js	Wed May 27 16:59:23 2015 +0200
@@ -50,7 +50,6 @@
                     jsonData: jsondata,
                     success: function(response) {
                         var json = Ext.JSON.decode(response.responseText);
-                        console.log(json);
                         Ext.Msg.show({
                             title: i18n.getMsg('success'),
                             autoScroll: true,
@@ -59,23 +58,36 @@
                         });
                     },
                     failure: function(response) {
-                    // TODO handle Errors correctly, especially AuthenticationTimeouts
                         var json = Ext.JSON.decode(response.responseText);
                         if (json) {
                             if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
                                 formPanel.setMessages(json.errors, json.warnings);
                             }
+                            // TODO Move this handling of 699 and 698 to a more central place!
+                            // TODO i18n
+                            if (json.message === "699" || json.message === "698") {
+                                /* This is the unauthorized message with the authentication
+                                    * redirect in the data */
 
-                            if(json.message){
-                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
+                                /* 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. */
+                                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);
+                            }
+                            else if(json.message){
+                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
                                     +' #'+json.message,
                                     Lada.getApplication().bundle.getMsg(json.message));
                             } else {
-                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
+                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
                                     Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
                             }
                         } else {
-                            Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
+                            Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
                                 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
                         }
                     }
@@ -152,7 +164,7 @@
     evalResponse: function(response) {
         var i18n = Lada.getApplication().bundle;
         var r = '';
-            r += response.totalCount;
+            r += response.data.length;
             r += ' ' + i18n.getMsg('probecreated');
             r += '<br/>';
             r += i18n.getMsg('probeids');
@@ -162,5 +174,11 @@
                 r += response.data[i].probeIdAlt
             }
         return r;
+    },
+
+    reload: function(btn) {
+        if (btn === 'yes') {
+            location.reload();
+        }
     }
 });

http://lada.wald.intevation.org