Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't inherit falcon.HTTPError #83

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions apphelpers/errors.py
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions apphelpers/rest/hug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down