diff --git a/apphelpers/errors.py b/apphelpers/errors.py index a3ef159..ebda430 100644 --- a/apphelpers/errors.py +++ b/apphelpers/errors.py @@ -1,47 +1,42 @@ -from falcon import HTTPError, status_codes - - -class BaseError(HTTPError): +class BaseError(Exception): # Whether to report this error to honeybadger report = True - status = status_codes.HTTP_500 - description: str = "Something went wrong" + code = 500 + msg = "Something went wrong" - def __init__(self, status=None, description=None): - super().__init__( - status=status or self.status, - description=description or self.description, - ) + def __init__(self, code=None, msg=None): + self.code = code or self.code + self.msg = msg or self.msg def to_dict(self): return { - "status": self.status, - "description": self.description, + "code": self.code, + "msg": self.msg, } class NotFoundError(BaseError): - status = status_codes.HTTP_404 - description = "Not Found" + code = 404 + msg = "Not Found" class AccessDenied(BaseError): - status = status_codes.HTTP_403 - description = "Access denied" + code = 403 + msg = "Access denied" class ValidationError(BaseError): - status = status_codes.HTTP_400 - description = "Invalid request" + code = 400 + msg = "Invalid request" class InvalidSessionError(BaseError): - status = status_codes.HTTP_401 - description = "Invalid session" + code = 401 + msg = "Invalid session" class ConflictError(BaseError): - status = status_codes.HTTP_409 - description = "Duplicate resource" + code = 409 + msg = "Duplicate resource" diff --git a/apphelpers/rest/hug.py b/apphelpers/rest/hug.py index 41ce8dc..4d92cfe 100644 --- a/apphelpers/rest/hug.py +++ b/apphelpers/rest/hug.py @@ -2,7 +2,7 @@ import hug from converge import settings -from falcon import HTTPForbidden, HTTPNotFound, HTTPUnauthorized +from falcon import HTTPError, HTTPForbidden, HTTPNotFound, HTTPUnauthorized from hug.decorators import wraps from apphelpers.db.peewee import dbtransaction @@ -63,7 +63,7 @@ def f_wrapped(*args, **kw): notify_honeybadger( honeybadger=hb, error=e, func=f, args=args, kwargs=kw ) - raise e + raise HTTPError(e.code, code=e.code, description=e.msg) except Exception as e: notify_honeybadger(