[FIX] Some improvement in exception handling.
authornoz (OpenERP) <noz@tinyerp.com>
Wed, 6 Jul 2011 07:15:46 +0000 (12:45 +0530)
committernoz (OpenERP) <noz@tinyerp.com>
Wed, 6 Jul 2011 07:15:46 +0000 (12:45 +0530)
bzr revid: noz@tinyerp.com-20110706071546-w9fcjdsbxg473a90

addons/base/controllers/main.py
addons/base/static/src/js/chrome.js

index 1a15d4e..f153c3d 100644 (file)
@@ -133,20 +133,26 @@ class Session(openerpweb.Controller):
         elif flag == 'backup':
             db = kw.get('db')
             password = kw.get('password')
-            
-            res = req.session.proxy("db").dump(password, db)
-            if res:
-                cherrypy.response.headers['Content-Type'] = "application/data"
-                cherrypy.response.headers['Content-Disposition'] = 'filename="' + db + '.dump"'
-                return base64.decodestring(res)
+            try:
+                res = req.session.proxy("db").dump(password, db)
+                if res:
+                    cherrypy.response.headers['Content-Type'] = "application/data"
+                    cherrypy.response.headers['Content-Disposition'] = 'filename="' + db + '.dump"'
+                    return base64.decodestring(res)
+            except Exception:
+                return {'error': 'Could not create backup !'}
             
         elif flag == 'restore':
             filename = kw.get('filename')
             db = kw.get('db')
             password = kw.get('password')
             
-            data = base64.encodestring(filename.file.read())
-            return req.session.proxy("db").restore(password, db, data)
+            try:
+                if filename:
+                    data = base64.encodestring(filename.file.read())
+                    return req.session.proxy("db").restore(password, db, data)
+            except Exception:
+                return {'error': 'Could not restore database !'}
         
         elif flag == 'change_password':
             old_password = kw.get('old_password')
index fb7b7ac..ef86595 100644 (file)
@@ -976,7 +976,9 @@ openerp.base.Database = openerp.base.Controller.extend({
                        self.rpc("/base/session/db_operation", {'flag': 'backup', 'db': db, 'password': password}, 
                        function(result) {
                                if (result && !result.error) {
-                                       self.notification.notify("Backup has been created for the database: '" + db + "'");
+                                       self.notification.notify("Backup Database", "Backup has been created for the database: '" + db + "'");
+                               } else if (result.error) {
+                                       self.notification.notify("Backup Database", result.error);
                                }
                        });
                });
@@ -998,7 +1000,9 @@ openerp.base.Database = openerp.base.Controller.extend({
                        self.rpc("/base/session/db_operation", {'flag': 'restore', 'db': db, 'password': password, 'new_db': new_db}, 
                        function(result) {
                                if (result && !result.error) {
-                                       self.notification.notify("You restored your database as: '" + new_db + "'");
+                                       self.notification.notify("Restore Database", "You restored your database as: '" + new_db + "'");
+                               } else if (result.error) {
+                                       self.notification.notify("Restore Database", result.error);
                                }
                        });
                });
@@ -1044,7 +1048,7 @@ openerp.base.Database = openerp.base.Controller.extend({
                        self.rpc("/base/session/db_operation", {'flag': 'change_password', 'old_password': old_pwd, 'new_password': new_pwd, 'confirm_password': confirm_pwd}, 
                        function(result) {
                                if (result && !result.error) {
-                                       self.notification.notify("Password has been changed successfully");
+                                       self.notification.notify("Changed Password", "Password has been changed successfully");
                                }
                        });
                });