blob: 6ddab7a9872dc2f3f985be54075df74d35810121 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
##############################################################################
# Copyright (c) 2017 ZTE Corporation and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import httplib
import connexion
from qtip.base import error
def check_endpoint_for_error(resource, operation=None):
def _decorator(func):
def _execute(name=None):
try:
return func(name), httplib.OK
except error.NotFoundError:
return connexion.problem(
httplib.NOT_FOUND,
'{} not found'.format(resource),
'Requested {} `{}` not found.'
.format(resource.lower(), name))
except error.ToBeDoneError:
return connexion.problem(
httplib.NOT_IMPLEMENTED,
'{} handler not implemented'.format(operation),
'Requested operation `{}` on {} not implemented.'
.format(operation.lower(), resource.lower()))
return _execute
return _decorator
|