[Kimchi-devel] [PATCHv3] Exception: fix exception details when not specified
lvroyce at linux.vnet.ibm.com
lvroyce at linux.vnet.ibm.com
Mon May 26 10:22:53 UTC 2014
From: Royce Lv <lvroyce at linux.vnet.ibm.com>
v2>v3, Because kimchi exception used unicode as msg, convert it to str
to make unicode encode work.
v1>v2, Add a new type of error to cover general schema validation error.
(per Sheldon's comments)
Not every validation error needs to translate for user,
we define user interested errors,
other developer interested error should report directly by schema validator,
and handled by developer directly.
fix exception handling for this situation.
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
Signed-off-by: Zheng Sheng Zhou <zhshzhou at linux.vnet.ibm.com>
---
src/kimchi/control/utils.py | 6 ++++--
src/kimchi/i18n.py | 1 +
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
index 5e63816..081bb81 100644
--- a/src/kimchi/control/utils.py
+++ b/src/kimchi/control/utils.py
@@ -98,8 +98,10 @@ def validate_params(params, instance, action):
try:
validator.validate(request)
except ValidationError, e:
- raise InvalidParameter(e.schema['error'], {'value': str(e.instance)})
-
+ if e.schema.get('error'):
+ raise InvalidParameter(e.schema['error'], {'value': str(e.instance)})
+ else:
+ raise InvalidParameter("KCHAPI0008E", {"err": str(e.message)})
class UrlSubNode(object):
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 25b703f..4ed13fe 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -30,6 +30,7 @@ messages = {
"KCHAPI0005E": _("Create is not allowed for %(resource)s"),
"KCHAPI0006E": _("Unable to parse JSON request"),
"KCHAPI0007E": _("This API only supports JSON"),
+ "KCHAPI0008E": _("Parameters does not match requirement in schema: %(err)s"),
"KCHASYNC0001E": _("Datastore is not initiated in the model object."),
"KCHASYNC0002E": _("Unable to start task due error: %(err)s"),
--
1.8.3.2
More information about the Kimchi-devel
mailing list