From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
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(a)linux.vnet.ibm.com>
Signed-off-by: Zheng Sheng Zhou <zhshzhou(a)linux.vnet.ibm.com>
---
src/kimchi/control/utils.py | 6 ++++--
src/kimchi/exception.py | 2 +-
src/kimchi/i18n.py | 1 +
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
index 5e63816..611b1c0 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":
e.message})
class UrlSubNode(object):
diff --git a/src/kimchi/exception.py b/src/kimchi/exception.py
index fcf60cc..5a292e0 100644
--- a/src/kimchi/exception.py
+++ b/src/kimchi/exception.py
@@ -62,7 +62,7 @@ class KimchiException(Exception):
# itself to a unicode string.
args[key] = unicode(value)
- return unicode(translation.gettext(text), 'utf-8') % args
+ return translation.gettext(text).encode('utf-8') % args
class NotFoundError(KimchiException):
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