Skip to content
Snippets Groups Projects
Commit 2dc630e8 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Create extra package for errors

parent cb1228c3
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,8 @@ def create_app():
app.register_blueprint(content_blueprint, url_prefix='/content')
from .corpora import corpora as corpora_blueprint
app.register_blueprint(corpora_blueprint, url_prefix='/corpora')
from .errors import errors as errors_blueprint
app.register_blueprint(errors_blueprint)
from .jobs import jobs as jobs_blueprint
app.register_blueprint(jobs_blueprint, url_prefix='/jobs')
from .main import main as main_blueprint
......
from flask import Blueprint
errors = Blueprint('errors', __name__)
from app.errors import handlers
from flask import render_template, request, jsonify
from . import main
from . import errors
@main.app_errorhandler(403)
@errors.app_errorhandler(403)
def forbidden(e):
if request.accept_mimetypes.accept_json and \
not request.accept_mimetypes.accept_html:
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
response = jsonify({'error': 'forbidden'})
response.status_code = 403
return response
return render_template('403.html.j2', title='Forbidden'), 403
return render_template('errors/403.html.j2', title='Forbidden'), 403
@main.app_errorhandler(404)
def page_not_found(e):
if request.accept_mimetypes.accept_json and \
not request.accept_mimetypes.accept_html:
@errors.app_errorhandler(404)
def not_found(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
response = jsonify({'error': 'not found'})
response.status_code = 404
return response
return render_template('404.html.j2', title='Not Found'), 404
return render_template('errors/404.html.j2', title='Not Found'), 404
@main.app_errorhandler(500)
@errors.app_errorhandler(413)
def payload_too_large(e):
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
response = jsonify({'error': 'payload too large'})
response.status_code = 413
return response
return render_template('errors/413.html.j2', title='Payload Too Large'), 413
@errors.app_errorhandler(500)
def internal_server_error(e):
if request.accept_mimetypes.accept_json and \
not request.accept_mimetypes.accept_html:
if (request.accept_mimetypes.accept_json
and not request.accept_mimetypes.accept_html):
response = jsonify({'error': 'internal server error'})
response.status_code = 500
return response
return render_template('500.html.j2', title='Internal Server Error'), 500
return render_template('errors/500.html.j2', title='Internal Server Error'), 500
......@@ -2,4 +2,4 @@ from flask import Blueprint
main = Blueprint('main', __name__)
from . import errors, views # noqa
from . import views # noqa
{% extends "nopaque.html.j2" %}
{% block page_content %}
<div class="col s12">
<p>This site is forbidden for you.</p>
</div>
{% endblock %}
{% extends "nopaque.html.j2" %}
{% block page_content %}
<div class="col s12">
<p>Site has not been found.</p>
</div>
{% endblock %}
{% extends "nopaque.html.j2" %}
{% block page_content %}
<div class="col s12">
<p>Internal Server Error. We are Sorry!</p>
</div>
{% endblock %}
{% extends 'nopaque.html.j2' %}
{% block page_content %}
<div class="container">
<h1>{{ title }}</h1>
<p class="light">{{ request.path }}</p>
<p>Alternatively, you can visit the <a href="{{ url_for('main.index') }}">Main Page</a> or read <a class="modal-trigger" href="#more-information-modal">more information</a> about this type of error.</p>
</div>
<div class="modal" id="more-information-modal">
<div class="modal-content">
<h4>{{ title }}</h4>
<p>The request contained valid data and was understood by the server, but the server is refusing action. This may be due to the user not having the necessary permissions for a resource or needing an account of some sort, or attempting a prohibited action (e.g. creating a duplicate record where only one is allowed). This code is also typically used if the request provided authentication by answering the WWW-Authenticate header field challenge, but the server did not accept that authentication. The request should not be repeated.</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn-flat modal-close waves-effect waves-green">Close</a>
</div>
</div>
{% endblock page_content %}
{% extends 'nopaque.html.j2' %}
{% block page_content %}
<div class="container">
<h1>{{ title }}</h1>
<p class="light">{{ request.path }}</p>
<p>Alternatively, you can visit the <a href="{{ url_for('main.index') }}">Main Page</a> or read <a class="modal-trigger" href="#more-information-modal">more information</a> about this type of error.</p>
</div>
<div class="modal" id="more-information-modal">
<div class="modal-content">
<h4>{{ title }}</h4>
<p>The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn-flat modal-close waves-effect waves-green">Close</a>
</div>
</div>
{% endblock page_content %}
{% extends 'nopaque.html.j2' %}
{% block page_content %}
<div class="container">
<h1>{{ title }}</h1>
<p class="light">{{ request.path }}</p>
<p>Alternatively, you can visit the <a href="{{ url_for('main.index') }}">Main Page</a> or read <a class="modal-trigger" href="#more-information-modal">more information</a> about this type of error.</p>
</div>
<div class="modal" id="more-information-modal">
<div class="modal-content">
<h4>{{ title }}</h4>
<p>The request is larger than the server is willing or able to process. Previously called "Request Entity Too Large".</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn-flat modal-close waves-effect waves-green">Close</a>
</div>
</div>
{% endblock page_content %}
{% extends 'nopaque.html.j2' %}
{% block page_content %}
<div class="container">
<h1>{{ title }}</h1>
<p class="light">{{ request.path }}</p>
<p>Alternatively, you can visit the <a href="{{ url_for('main.index') }}">Main Page</a> or read <a class="modal-trigger" href="#more-information-modal">more information</a> about this type of error.</p>
</div>
<div class="modal" id="more-information-modal">
<div class="modal-content">
<h4>{{ title }}</h4>
<p>A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn-flat modal-close waves-effect waves-green">Close</a>
</div>
</div>
{% endblock page_content %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment