diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-03-30 18:27:01 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-04-01 22:25:53 +0300 |
| commit | a9f4308bb770c3cf1d0f521b876941463273d248 (patch) | |
| tree | 3931ff6bc564e8f03821a41d79cc84e61ee526f9 /src/server/rz_req_handling.py | |
| parent | a5425d62477da1b7cfea5f97fc7e2492a1589cf3 (diff) | |
common_rest_req_exception_handler():
- allow request handling to raise exceptions
- call proper response builder according to exception
Diffstat (limited to 'src/server/rz_req_handling.py')
| -rw-r--r-- | src/server/rz_req_handling.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/server/rz_req_handling.py b/src/server/rz_req_handling.py index 2960874c..4be9d553 100644 --- a/src/server/rz_req_handling.py +++ b/src/server/rz_req_handling.py @@ -46,6 +46,24 @@ def common_resp_handle__client_error(data=None, error=None, status=400): def common_resp_handle__server_error(data=None, error=None, status=500): return __common_resp_handle(data, error, status) +def common_rest_req_exception_handler(rest_API_endpoint): + + @wraps(rest_API_endpoint) + def rest_API_endpoint__decorated(*args, **kwargs): + try: + return rest_API_endpoint(*args, **kwargs) + except API_Exception__bad_request as e: + log.exception(e) + return common_resp_handle__client_error(error=e) # currently blame client for all DNFs + except RZDoc_Exception__not_found as e: + log.exception(e) + return common_resp_handle__client_error(error=e) # currently blame client for all DNFs + except Exception as e: + log.exception(e) + return common_resp_handle__server_error(error=e) + + return rest_API_endpoint__decorated + def make_response__json(status=200, data={}): """ Construct a json response with proper content-type header |
