This repository has been archived by the owner on Oct 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from automationator/master
Fixes error handlers
- Loading branch information
Showing
5 changed files
with
33 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Blueprint | ||
|
||
bp = Blueprint('errors', __name__) | ||
|
||
from project.errors import handlers |
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,24 @@ | ||
from flask import request | ||
|
||
from project import db | ||
from project.errors import bp | ||
from project.api.errors import error_response | ||
from project.gui.views import DefaultView | ||
|
||
|
||
@bp.app_errorhandler(404) | ||
def not_found_error(error): | ||
if request.path.startswith('/api/'): | ||
return error_response(404, 'API endpoint not found') | ||
else: | ||
return DefaultView().render('errors/404.html'), 404 | ||
|
||
|
||
@bp.app_errorhandler(500) | ||
def internal_error(error): | ||
if request.path.startswith('/api/'): | ||
db.session.rollback() | ||
return error_response(500, 'Internal server error') | ||
else: | ||
|
||
return DefaultView().render('errors/500.html'), 500 |
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 was deleted.
Oops, something went wrong.