summaryrefslogtreecommitdiffstats
path: root/qtip/api/controllers/common.py
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-03-22 07:45:48 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-03-22 07:45:48 +0000
commit6f553fb49184b05c6765c0bbc352f1f83bc586cc (patch)
treee02348b017d3781baf40a855aa45053f85372481 /qtip/api/controllers/common.py
parent829bf5311cc8db0e2295cf6a26be5cdea88e3db8 (diff)
parent1899d336b7172809b8ff8439bec2038d83e976a0 (diff)
Merge "provide get_one_exceptions to unify get_xx process" into stable/danube
Diffstat (limited to 'qtip/api/controllers/common.py')
-rw-r--r--qtip/api/controllers/common.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/qtip/api/controllers/common.py b/qtip/api/controllers/common.py
new file mode 100644
index 00000000..6cabbc7f
--- /dev/null
+++ b/qtip/api/controllers/common.py
@@ -0,0 +1,19 @@
+import httplib
+
+import connexion
+
+from qtip.base import error
+
+
+def get_one_exceptions(resource):
+ def _decorator(func):
+ def _execute(name):
+ try:
+ return func(name), httplib.OK
+ except error.NotFoundError:
+ return connexion.problem(
+ httplib.NOT_FOUND,
+ '{} Not Found'.format(resource),
+ 'Requested {} `{}` not found.'.format(resource, name))
+ return _execute
+ return _decorator