-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-gateway): add common service errors (#506)
- Loading branch information
Michael Brewer
authored
Jul 6, 2021
1 parent
2473480
commit 33f80fd
Showing
5 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APPLICATION_JSON = "application/json" | ||
PLAIN_TEXT = "plain/text" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from http import HTTPStatus | ||
|
||
|
||
class ServiceError(Exception): | ||
"""Service Error""" | ||
|
||
def __init__(self, status_code: int, msg: str): | ||
""" | ||
Parameters | ||
---------- | ||
status_code: int | ||
Http status code | ||
msg: str | ||
Error message | ||
""" | ||
self.status_code = status_code | ||
self.msg = msg | ||
|
||
|
||
class BadRequestError(ServiceError): | ||
"""Bad Request Error""" | ||
|
||
def __init__(self, msg: str): | ||
super().__init__(HTTPStatus.BAD_REQUEST, msg) | ||
|
||
|
||
class UnauthorizedError(ServiceError): | ||
"""Unauthorized Error""" | ||
|
||
def __init__(self, msg: str): | ||
super().__init__(HTTPStatus.UNAUTHORIZED, msg) | ||
|
||
|
||
class NotFoundError(ServiceError): | ||
"""Not Found Error""" | ||
|
||
def __init__(self, msg: str = "Not found"): | ||
super().__init__(HTTPStatus.NOT_FOUND, msg) | ||
|
||
|
||
class InternalServerError(ServiceError): | ||
"""Internal Server Error""" | ||
|
||
def __init__(self, message: str): | ||
super().__init__(HTTPStatus.INTERNAL_SERVER_ERROR, message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters