This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
59cccc6
commit 8770962
Showing
4 changed files
with
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,7 @@ __pycache__ | |
.env | ||
|
||
# Instance | ||
instance | ||
instance | ||
|
||
# IDE | ||
.vscode |
Empty file.
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,23 @@ | ||
""" | ||
This module handlers all exceptions regarding HTTP error codes | ||
""" | ||
|
||
from flask import json, Blueprint | ||
from werkzeug.exceptions import HTTPException | ||
|
||
errors_bp = Blueprint('errors', __name__) | ||
|
||
|
||
@errors_bp.app_errorhandler(HTTPException) | ||
def handle_exception(e): | ||
"""Return JSON instead of HTML for HTTP errors.""" | ||
# start with the correct headers and status code from the error | ||
response = e.get_response() | ||
# replace the body with JSON | ||
response.data = json.dumps({ | ||
"code": e.code, | ||
"name": e.name, | ||
"description": e.description, | ||
}) | ||
response.content_type = "application/json" | ||
return response |
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