[Kimchi-devel] [PATCH 3/3] refator exception: Example of use

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 31 18:20:53 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

This is just an example with which changes are needed in backend and UI to
properly show the error messages translated to the user

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 src/kimchi/control/base.py     |    5 ++++-
 src/kimchi/model/vms.py        |    4 +++-
 ui/js/src/kimchi.guest_main.js |    4 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index f50ff6e..e50720a 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -30,8 +30,9 @@ import kimchi.template
 from kimchi.control.utils import get_class_name, internal_redirect, model_fn
 from kimchi.control.utils import parse_request, validate_method
 from kimchi.control.utils import validate_params
-from kimchi.exception import InvalidOperation, InvalidParameter
+from kimchi.exception import InvalidOperation, InvalidParameter, KimchiError
 from kimchi.exception import MissingParameter, NotFoundError,  OperationFailed
+from kimchi.template import HTTPError
 
 
 class Resource(object):
@@ -82,6 +83,8 @@ class Resource(object):
                 raise cherrypy.HTTPError(500, "Operation Failed: '%s'" % msg)
             except NotFoundError, msg:
                 raise cherrypy.HTTPError(404, "Not found: '%s'" % msg)
+            except KimchiError, e:
+                raise HTTPError(400, e)
 
         wrapper.__name__ = action_name
         wrapper.exposed = True
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index e9f7753..374bbe0 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -30,8 +30,9 @@ from cherrypy.process.plugins import BackgroundTask
 
 from kimchi import vnc
 from kimchi import xmlutils
-from kimchi.exception import InvalidOperation, InvalidParameter
+from kimchi.exception import KimchiError, InvalidOperation, InvalidParameter
 from kimchi.exception import NotFoundError, OperationFailed
+from kimchi.model.__messages__ import ERR_VM_START_FAILED
 from kimchi.model.config import CapabilitiesModel
 from kimchi.model.templates import TemplateModel
 from kimchi.model.utils import get_vm_name
@@ -346,6 +347,7 @@ class VMModel(object):
             vnc.remove_proxy_token(name)
 
     def start(self, name):
+        raise KimchiError("Go to Homepage", {})
         dom = self.get_vm(name, self.conn)
         dom.create()
 
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index 8467f3f..2fadbe5 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -25,8 +25,8 @@ kimchi.initVmButtonsAction = function() {
             $(this).addClass('loading');
             kimchi.startVM($(this).data('vm'), function(result) {
                 kimchi.listVmsAuto();
-            }, function() {
-                kimchi.message.error(i18n['msg.fail.start']);
+            }, function(err) {
+                kimchi.message.error(err.responseJSON.message);
             });
         } else {
             event.preventDefault();
-- 
1.7.10.4




More information about the Kimchi-devel mailing list