Skip to content

Commit

Permalink
Merge pull request #1 from MoBagel/feature/add-more-codes
Browse files Browse the repository at this point in the history
adding more codes
  • Loading branch information
schwannden authored Jul 20, 2022
2 parents 52b705b + 2aac6c9 commit e74a0e6
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 119 deletions.
63 changes: 56 additions & 7 deletions awesome_exception/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ def __init__(
status_code: int,
message: str,
error_code: Optional[str] = None,
args: dict = {},
args: Optional[dict] = None,
):
args = args if args else {}
self.status_code = status_code
self.detail = {"message": message, **args}
self.error_code = error_code if error_code is not None else str(status_code)


class BadRequest(HTTPException):
def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=400,
message="Bad Request: %s" % message,
Expand All @@ -29,7 +32,9 @@ def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):


class Unauthorized(HTTPException):
def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=401,
message="Unauthorized: %s" % message,
Expand All @@ -38,8 +43,22 @@ def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
)


class Forbidden(HTTPException):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=403,
message="Forbidden: %s" % message,
error_code=error_code,
args=args,
)


class NotFound(HTTPException):
def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=404,
message="Not Found: %s" % message,
Expand All @@ -49,7 +68,9 @@ def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):


class ResourceGone(HTTPException):
def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=410,
message="Resource Gone: %s" % message,
Expand All @@ -59,7 +80,9 @@ def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):


class UnprocessableEntity(HTTPException):
def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=422,
message="Unprocessable Entity: %s" % message,
Expand All @@ -69,10 +92,36 @@ def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):


class InternalServerError(HTTPException):
def __init__(self, message, error_code: Optional[str] = None, args: dict = {}):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=500,
message="Internal Server Error: %s" % message,
error_code=error_code,
args=args,
)


class NotImplemented(HTTPException):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=501,
message="Not Implemented: %s" % message,
error_code=error_code,
args=args,
)


class ServiceUnavailable(HTTPException):
def __init__(
self, message, error_code: Optional[str] = None, args: Optional[dict] = None
):
super().__init__(
status_code=503,
message="Service Unavailable: %s" % message,
error_code=error_code,
args=args,
)
Loading

0 comments on commit e74a0e6

Please sign in to comment.