This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
5 changed files
with
93 additions
and
1 deletion.
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,51 @@ | ||
from typing import Optional | ||
|
||
from flask_utils.errors.base_class import _BaseFlaskException | ||
|
||
|
||
class MethodNotAllowedError(_BaseFlaskException): | ||
"""This is the MethodNotAllowedError exception class. | ||
When raised, it will return 405 status code with the message and solution provided. | ||
:param msg: The message to be displayed in the error. | ||
:type msg: str | ||
:param solution: The solution to the error. | ||
:type solution: Optional[str] | ||
:Example: | ||
.. code-block:: python | ||
from flask_utils.errors import MethodNotAllowedError | ||
# Inside a Flask route | ||
@app.route('/example', methods=['POST']) | ||
def example_route(): | ||
... | ||
if some_condition: | ||
raise MethodNotAllowedError("This is a not allowed error.") | ||
The above code would return the following JSON response from Flask: | ||
.. code-block:: json | ||
{ | ||
"success": false, | ||
"error": { | ||
"type": "Method Not Allowed", | ||
"name": "Method Not Allowed", | ||
"message": "This is a Method Not Allowed error.", | ||
"solution": "Try again." | ||
}, | ||
"code": 404 | ||
} | ||
.. versionadded:: 0.1.0 | ||
""" | ||
|
||
def __init__(self, msg: str, solution: Optional[str] = "Try again.") -> None: | ||
self.name = "Method Not Allowed" | ||
self.msg = msg | ||
self.solution = solution | ||
self.status_code = 405 |
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