-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom exceptions and handling for web errors (#42)
- Loading branch information
Showing
2 changed files
with
76 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Custom exceptions for Areion. | ||
These are globally handled in the core server. | ||
""" | ||
|
||
|
||
class HttpError(Exception): | ||
"""Base class for HTTP errors.""" | ||
|
||
status_code: int = 500 | ||
message: str = "Internal Server Error" | ||
|
||
def __init__(self, message: str = None): | ||
if message: | ||
self.message = message | ||
super().__init__(self.message) | ||
|
||
def __str__(self): | ||
return str(self.status_code) + " " + self.message | ||
|
||
|
||
class BadRequestError(HttpError): | ||
"""400 Bad Request.""" | ||
|
||
status_code = 400 | ||
message = "Bad Request" | ||
|
||
|
||
class UnauthorizedError(HttpError): | ||
"""401 Unauthorized.""" | ||
|
||
status_code = 401 | ||
message = "Unauthorized" | ||
|
||
|
||
class ForbiddenError(HttpError): | ||
"""403 Forbidden.""" | ||
|
||
status_code = 403 | ||
message = "Forbidden" | ||
|
||
|
||
class NotFoundError(HttpError): | ||
"""404 Not Found.""" | ||
|
||
status_code = 404 | ||
message = "Not Found" | ||
|
||
|
||
class MethodNotAllowedError(HttpError): | ||
"""405 Method Not Allowed.""" | ||
|
||
status_code = 405 | ||
message = "Method Not Allowed" | ||
|
||
|
||
class InternalServerError(HttpError): | ||
"""500 Internal Server Error.""" | ||
|
||
status_code = 500 | ||
message = "Internal Server Error" |
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