Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #51 from mkiwala/no-such-entity-410
Browse files Browse the repository at this point in the history
Make 404 configurable
  • Loading branch information
mkiwala committed Feb 23, 2016
2 parents 7acb2e1 + 994dabf commit ec44bf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ptero_common/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class NoSuchEntityError(RuntimeError):
pass
18 changes: 18 additions & 0 deletions ptero_common/view_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from functools import wraps
from os import environ
from ptero_common.exceptions import NoSuchEntityError


NO_SUCH_ENTITY_STATUS_CODE = int(environ.get(
'PTERO_NO_SUCH_ENTITY_STATUS_CODE', 404))


def handles_no_such_entity_error(target):
@wraps(target)
def wrapper(*args, **kwargs):
try:
result = target(*args, **kwargs)
except NoSuchEntityError as e:
return {'error': e.message}, NO_SUCH_ENTITY_STATUS_CODE
return result
return wrapper

0 comments on commit ec44bf9

Please sign in to comment.