Skip to content

Commit 66aa6f8

Browse files
committed
Improves error handling with custom pages
Adds custom 404 and 500 error pages to improve user experience when encountering errors.
1 parent 2a0040d commit 66aa6f8

File tree

6 files changed

+155
-3
lines changed

6 files changed

+155
-3
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"Bash(pytest:*)",
99
"Bash(pip search:*)",
1010
"Bash(psql:*)",
11-
"Bash(OPTIMAP_LOGGING_LEVEL=WARNING python manage.py test tests.test_work_landing_page.PublicationStatusVisibilityTest)"
11+
"Bash(OPTIMAP_LOGGING_LEVEL=WARNING python manage.py test tests.test_work_landing_page.PublicationStatusVisibilityTest)",
12+
"Bash(curl:*)"
1213
],
1314
"deny": [],
1415
"ask": []

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- **Temporal extent contribution** - Users can now contribute temporal extent (start/end dates) in addition to spatial extent. Works can be published with either spatial, temporal, or both extents. Supports flexible date formats: YYYY, YYYY-MM, YYYY-MM-DD.
88
- **Complete status workflow documentation** - Documented all 6 publication statuses (Draft, Harvested, Contributed, Published, Testing, Withdrawn) with workflow transitions and visibility rules in README.md.
9+
- **Custom error pages** - Added styled 404 and 500 error pages matching application design with navigation links and help information directing users to About and Accessibility pages.
910
- **Map popup enhancement** - Added "View Publication Details" button to map popups linking to work landing pages.
1011
- **Admin unpublish functionality** - Admins can unpublish works, changing status from Published to Draft.
1112
- **RSS/Atom feed harvesting support** - Added support for harvesting publications from RSS/Atom feeds in addition to OAI-PMH.
@@ -15,7 +16,7 @@
1516
### Changed
1617

1718
- **Unified contribution workflow** - Single "Submit contribution" button for both spatial and temporal extent. Users can submit either or both in one action.
18-
- **Unified admin control panel** - Consolidated admin status display, publish/unpublish buttons, and "Edit in Admin" link into single highlighted box at top of work landing page.
19+
- **Unified admin control panel** - Consolidated admin status display, publish/unpublish buttons, provenance information, and "Edit in Admin" link into single highlighted box at top of work landing page. Provenance is collapsible.
1920
- **Improved text wrapping** - Page titles and abstract text now properly wrap on narrow windows instead of overflowing.
2021
- **Unified URL structure** - Changed ID-based URLs from `/publication/<id>/` to `/work/<id>/` for consistency with DOI-based URLs.
2122
- **Refactored views_geometry.py** - Eliminated code duplication by making DOI-based functions wrap ID-based functions. Reduced from 375 to 240 lines (~36% reduction).

optimap/urls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
re_path(r'^robots.txt', RobotsView.as_view(), name="robots_file"),
4343
]
4444

45+
# Custom error handlers
46+
handler404 = 'publications.views.custom_404'
47+
handler500 = 'publications.views.custom_500'
48+
4549
# Context processor for the site
4650
from django.contrib.sites.shortcuts import get_current_site
4751
from django.utils.functional import SimpleLazyObject

publications/templates/404.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{% extends "base.html" %}
2+
3+
{% block title %}Page Not Found - {% endblock %}
4+
5+
{% block navbar %}
6+
<ul class="nav navbar-nav">
7+
{% if request.user.is_authenticated %}
8+
{% include "authenticated_menu_snippet.html" %}
9+
{% else %}
10+
{% include "menu_snippet.html" %}
11+
{% endif %}
12+
</ul>
13+
{% endblock %}
14+
15+
{% block content %}
16+
<div class="row justify-content-center">
17+
<div class="col-md-8 col-lg-6 py-5">
18+
<div class="text-center mb-4">
19+
<i class="fas fa-map-marked-alt" style="font-size: 5rem; color: #158F9B;"></i>
20+
</div>
21+
22+
<h1 class="text-center mb-4">Page Not Found</h1>
23+
24+
<div class="alert alert-warning">
25+
<p class="mb-3">
26+
<strong>Oops!</strong> The page you're looking for doesn't exist or has been moved.
27+
</p>
28+
<p class="mb-0">
29+
This could happen if:
30+
</p>
31+
<ul class="mb-0">
32+
<li>The URL was mistyped</li>
33+
<li>The publication or resource has been removed</li>
34+
<li>The link you followed is outdated</li>
35+
</ul>
36+
</div>
37+
38+
<div class="card mt-4">
39+
<div class="card-body">
40+
<h5 class="card-title"><i class="fas fa-compass"></i> Where would you like to go?</h5>
41+
<div class="list-group list-group-flush">
42+
<a href="/" class="list-group-item list-group-item-action">
43+
<i class="fas fa-home"></i> Home - View the map
44+
</a>
45+
<a href="/works/" class="list-group-item list-group-item-action">
46+
<i class="fas fa-list"></i> Browse all works
47+
</a>
48+
<a href="/contribute/" class="list-group-item list-group-item-action">
49+
<i class="fas fa-hands-helping"></i> Contribute metadata
50+
</a>
51+
<a href="/about/" class="list-group-item list-group-item-action">
52+
<i class="fas fa-info-circle"></i> About OPTIMAP
53+
</a>
54+
</div>
55+
</div>
56+
</div>
57+
58+
<div class="alert alert-info mt-4">
59+
<h6 class="mb-2"><i class="fas fa-question-circle"></i> Need help?</h6>
60+
<p class="mb-2">
61+
If you think this is an error or need assistance, please visit:
62+
</p>
63+
<ul class="mb-0">
64+
<li><a href="/about/" class="alert-link">About page</a> - Contact information and support</li>
65+
<li><a href="/accessibility/" class="alert-link">Accessibility page</a> - Accessibility features and help</li>
66+
</ul>
67+
</div>
68+
</div>
69+
</div>
70+
{% endblock %}

publications/templates/500.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{% extends "base.html" %}
2+
3+
{% block title %}Server Error - {% endblock %}
4+
5+
{% block navbar %}
6+
<ul class="nav navbar-nav">
7+
{% if request.user.is_authenticated %}
8+
{% include "authenticated_menu_snippet.html" %}
9+
{% else %}
10+
{% include "menu_snippet.html" %}
11+
{% endif %}
12+
</ul>
13+
{% endblock %}
14+
15+
{% block content %}
16+
<div class="row justify-content-center">
17+
<div class="col-md-8 col-lg-6 py-5">
18+
<div class="text-center mb-4">
19+
<i class="fas fa-exclamation-triangle" style="font-size: 5rem; color: #9B2115;"></i>
20+
</div>
21+
22+
<h1 class="text-center mb-4">Server Error</h1>
23+
24+
<div class="alert alert-danger">
25+
<p class="mb-3">
26+
<strong>Something went wrong on our end.</strong> We're sorry for the inconvenience.
27+
</p>
28+
<p class="mb-0">
29+
Our team has been notified and is working to fix the issue. Please try again in a few moments.
30+
</p>
31+
</div>
32+
33+
<div class="card mt-4">
34+
<div class="card-body">
35+
<h5 class="card-title"><i class="fas fa-compass"></i> What can you do?</h5>
36+
<div class="list-group list-group-flush">
37+
<a href="/" class="list-group-item list-group-item-action">
38+
<i class="fas fa-home"></i> Go to home page
39+
</a>
40+
<a href="/works/" class="list-group-item list-group-item-action">
41+
<i class="fas fa-list"></i> Browse all works
42+
</a>
43+
<a href="/contribute/" class="list-group-item list-group-item-action">
44+
<i class="fas fa-hands-helping"></i> Contribute metadata
45+
</a>
46+
</div>
47+
</div>
48+
</div>
49+
50+
<div class="alert alert-info mt-4">
51+
<h6 class="mb-2"><i class="fas fa-question-circle"></i> Need to report this error?</h6>
52+
<p class="mb-2">
53+
If this problem persists, please let us know:
54+
</p>
55+
<ul class="mb-0">
56+
<li><a href="/about/" class="alert-link">About page</a> - Contact information and support</li>
57+
<li><a href="/accessibility/" class="alert-link">Accessibility page</a> - Accessibility features and help</li>
58+
</ul>
59+
</div>
60+
</div>
61+
</div>
62+
{% endblock %}

publications/views.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,4 +787,18 @@ def work_landing_by_id(request, pub_id):
787787
"show_provenance": is_admin,
788788
"use_id_urls": True, # Flag to use ID-based URLs in template
789789
}
790-
return render(request, "work_landing_page.html", context)
790+
return render(request, "work_landing_page.html", context)
791+
792+
793+
# ------------------------------
794+
# Error Handlers
795+
# ------------------------------
796+
797+
def custom_404(request, exception=None):
798+
"""Custom 404 error handler"""
799+
return render(request, '404.html', status=404)
800+
801+
802+
def custom_500(request):
803+
"""Custom 500 error handler"""
804+
return render(request, '500.html', status=500)

0 commit comments

Comments
 (0)