Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Bug 791415] Add pretty 404 and 500 error pages.

  • Loading branch information...
commit af3483b61b5b40d8928322ded4e9a6650497ee14 1 parent 5eb748e
@mythmon authored
View
33 fjord/base/templates/404.html
@@ -1,15 +1,18 @@
-<!DOCTYPE html>
-<html LANG="{{ LANG }}" dir="{{ DIR }}">
- <head>
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
- <title>{{ _('Page not found') }}</title>
- </head>
- <body>
- <h1>{{ _('Page not found') }}</h1>
- <p>
- {% trans %}
- Sorry, but we couldn't find the page you're looking for.
- {% endtrans %}
- </p>
- </body>
-</html>
+{% extends "base.html" %}
+
+{% block page_title %}{{ _('Not Found') }}{% endblock %}
+
+{% block content %}
+ <div class="col"></div>
+ <div class="col wide">
+ <div class="block">
+ <h1>{{ _('Not Found') }}</h1>
+ <p>
+ {{ _('The document could not be found.') }}
+ </p>
+ <p>
+ <a href="/">{{ _('Return to the dashboard.') }}</a>
+ </p>
+ </div>
+ </div>
+{% endblock %}
View
43 fjord/base/templates/500.html
@@ -1,15 +1,40 @@
+{# This doesn't extend base.html, because base makes assumptions about the
+ # environment that aren't valid when rendering an exception.
+ #}
+
<!DOCTYPE html>
-<html LANG="{{ LANG }}" dir="{{ DIR }}">
+<html lang="{{ LANG }}" dir="{{ DIR }}">
<head>
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
- <title>{{ _('Something went wrong!') }}</title>
+ <title>{{ _('Something has gone horribly wrong') }} :: Firefox Input</title>
+
+ {{ css('base') }}
+
+ {# Settings isn't available when rendering this page, so hard code the static url.
+ # If this turns out to be the wrong setting, oh well, it's just a favicon. #}
+ <link rel="shortcut icon" type="image/png" href="/static/img/favicon.png"/>
</head>
<body>
- <h1>{{ _('Page not found') }}</h1>
- <p>
- {% trans %}
- Sorry, but something went wrong.
- {% endtrans %}
- </p>
+ <header>
+ <h1 class="title"><a href="{{ url('dashboard') }}">
+ {% trans %}
+ <strong>Firefox</strong> Input
+ {% endtrans %}
+ </a></h1>
+
+ <ul>
+ <li><a class="dashboard" href="{{ url('dashboard') }}"><span>{{ _('Dashboard') }}</span></a></li>
+ </ul>
+ </header>
+
+ <div id="content">
+ <div class="col"></div>
+ <div class="col wide">
+ <div class="block">
+ <h1>{{ _('Something has gone horribly wrong.') }}</h1>
+ <p>{{ _('There was a problem on the server.') }}</p>
+ <p><a href="{{ url('dashboard') }}">{{ _('Return to the dashboard.') }}</a></p>
+ </div>
+ </div>
+ </div>
</body>
</html>
View
4 fjord/base/templates/base.html
@@ -24,9 +24,9 @@
{% block site_header %}
<header>
- <h1 class="title"><a href="#">
+ <h1 class="title"><a href="/">
{% trans %}
- <strong>Firefox</strong> Input Dashboard
+ <strong>Firefox</strong> Input
{% endtrans %}
</a></h1>
View
16 fjord/base/tests/test_views.py
@@ -2,6 +2,7 @@
from fjord.base import views
from fjord.base.tests import LocalizingClient, reverse
+from fjord.base.views import IntentionalException
from fjord.search.tests import ElasticTestCase
@@ -49,3 +50,18 @@ def connect(self):
finally:
views.test_memcached = test_memcached
+
+
+class ErrorTesting(ElasticTestCase):
+ client_class = LocalizingClient
+
+ def test_404(self):
+ request = self.client.get('/a/path/that/should/never/exist')
+ eq_(request.status_code, 404)
+ self.assertTemplateUsed(request, '404.html')
+
+ def test_500(self):
+ with self.assertRaises(IntentionalException) as cm:
+ self.client.get('/services/throw-error')
+
+ eq_(type(cm.exception), IntentionalException)
View
6 fjord/base/urls.py
@@ -3,10 +3,10 @@
urlpatterns = patterns('fjord.base.views',
-
url(r'^$', 'home_view', name='home_view'),
- url(r'^about$', redirect_to, {'url': 'stub'}, name='about'),
+ url(r'^services/monitor$', 'monitor_view', name='services-monitor'),
+ url(r'^services/throw-error$', 'throw_error', name='throw-error'),
- url(r'^services/monitor$', 'monitor_view', name='services-monitor')
+ url(r'^about$', redirect_to, {'url': 'stub'}, name='about'),
)
View
18 fjord/base/views.py
@@ -2,7 +2,8 @@
import socket
from django.conf import settings
-from django.shortcuts import render
+from django.http import Http404
+from django.shortcuts import render, render_to_response
from django.views.decorators.cache import never_cache
from celery.messaging import establish_connection
@@ -143,3 +144,18 @@ def monitor_view(request):
{'component_status': status,
'status_summary': status_summary},
status=status_code)
+
+
+class IntentionalException(Exception):
+ pass
+
+
+def throw_error(request):
+ """Throw an error for testing purposes. Disabled in production."""
+
+ # If both of these are false, we are likely on a production server, where
+ # providing an end point to throw errors would be a bad thing.
+ if settings.SHOW_STAGE_NOTICE or settings.DEBUG:
+ raise IntentionalException("Error raised for testing purposes.")
+ else:
+ raise Http404
View
1  fjord/urls.py
@@ -33,6 +33,7 @@
(r'^admin/', include(admin.site.urls)),
)
+
## In DEBUG mode, serve media files through Django.
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
Please sign in to comment.
Something went wrong with that request. Please try again.