# HG changeset patch # User Benoît Allard # Date 1414424778 -3600 # Node ID 3a56d5501ffa881b72a29f9dcb08f6815d6d40e3 # Parent 584587a000a2c3232525e35c8d20478a7244e662 Add HTTP error handling diff -r 584587a000a2 -r 3a56d5501ffa farol/main.py --- a/farol/main.py Mon Oct 27 15:08:29 2014 +0100 +++ b/farol/main.py Mon Oct 27 16:46:18 2014 +0100 @@ -87,6 +87,13 @@ def makeId(string): return secure_filename(string) +@app.errorhandler(400) +@app.errorhandler(404) +@app.errorhandler(405) +@app.errorhandler(500) +def error_page(error): + return render_template('error.j2', e=error), getattr(error, 'code', 500) + @app.route('/') def welcome(): return render_template('welcome.j2', diff -r 584587a000a2 -r 3a56d5501ffa farol/templates/base.j2 --- a/farol/templates/base.j2 Mon Oct 27 15:08:29 2014 +0100 +++ b/farol/templates/base.j2 Mon Oct 27 16:46:18 2014 +0100 @@ -23,107 +23,83 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -#} +{% extends "layout.j2" %} + {% from "macros.j2" import modal, POST_button -%} - +{% block navbar %} + {% if has_current %} + Document + {% endif %} + {% if products %} + + {% endif %} + {% if vulnerabilities %} + + {% endif %} + {% if has_current %} +
  • + {% if error %} + + {% else %} + + {% endif %} +
  • + {% endif %} +{% endblock %} - - - - Farol - {% block title %}{% endblock %} - - - - - - - + {% endfor %} + + + {% endif %} +{% endblock %} + +{% block pre_content %} {% if has_current %} {% for element in cache %} {# Put the modals for the load action here #} @@ -137,32 +113,20 @@ {% endcall %} {% endfor %} {% endif %} -
    - {% with messages = get_flashed_messages(with_categories=True) %} - {% if messages %} -
    - {% for category, message in messages %} - {% if category == 'message' %}{% set category = "info" %}{% endif %} -
    {{ message }}
    - {% endfor %} -
    - {% endif %} - {% endwith %} -
    - - {% block content %}{% endblock %} + {% with messages = get_flashed_messages(with_categories=True) %} + {% if messages %} +
    + {% for category, message in messages %} + {% if category == 'message' %}{% set category = "info" %}{% endif %} +
    {{ message }}
    + {% endfor %}
    - {% if config.DEBUG and not config.DEBUG_SURE %} -
    DEBUG: This application is running in debug mode. See the about page for more Details
    {% endif %} -
    - - - + {% endwith %} +{% endblock %} + +{% block post_content %} + {% if config.DEBUG and not config.DEBUG_SURE %} +
    DEBUG: This application is running in debug mode. See the about page for more Details
    + {% endif %} +{% endblock %} diff -r 584587a000a2 -r 3a56d5501ffa farol/templates/error.j2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/farol/templates/error.j2 Mon Oct 27 16:46:18 2014 +0100 @@ -0,0 +1,15 @@ +{% extends "layout.j2" %} + +{% block title %}{{ e }}{% endblock %} + +{% block content %} + +{% if e.description %}

    {{ e.description }}


    {% endif %} +{% if e.code != 404 %} +

    Software are not without bugs. Looks like, you found one ... A trace has been written to the logs.

    +

    If you keep coming to this page, you might want to delete your document, and start again with a fresh one ...

    +
    {{ POST_button(url_for('document.delete'), text="Delete document", style="btn-danger") }}
    +{% endif %} +{% endblock %} diff -r 584587a000a2 -r 3a56d5501ffa farol/templates/layout.j2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/farol/templates/layout.j2 Mon Oct 27 16:46:18 2014 +0100 @@ -0,0 +1,83 @@ +{# +# Description: +# Web Template used in Farol Design +# +# Authors: +# Benoît Allard +# +# Copyright: +# Copyright (C) 2014 Greenbone Networks GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +-#} + +{% from "macros.j2" import modal, POST_button -%} + + + + + + + Farol - {% block title %}{% endblock %} + + + + + + + +
    + {% block pre_content %}{% endblock %} +
    + {% block content %}{% endblock %} +
    + {% block post_content %}{% endblock %} +
    + + +