Skip to content

Commit

Permalink
details for error messages and error page verbiage
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmst committed Dec 11, 2024
1 parent f2f57e1 commit ab8c53d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bloom_nofos/bloom_nofos/templates/400.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% extends 'base.html' %}

{% block title %}
{% if status %}{{ status }}{% else %}400{% endif %} bruv, oops — Bad request
{% if status %}{{ status }}{% else %}400{% endif %} - Bad Request
{% endblock %}


{% block content %}
<h1 class="font-heading-xl margin-y-0">{% if status %}{{ status }}{% else %}400{% endif %} bruv, oops</h1>
<h1 class="font-heading-xl margin-y-0">{% if status %}{{ status }}{% else %}400{% endif %} Error</h1>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% elif error_message_html %}
Expand Down
8 changes: 4 additions & 4 deletions bloom_nofos/bloom_nofos/templates/404.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% extends 'base.html' %}

{% block title %}
404 dawg, sorry — Page not found
404 - Page Not Found
{% endblock %}


{% block content %}
<h1 class="font-heading-xl margin-y-0">404 dawg, sorry</h1>
<p>No fos here or anything else.</p>
<p>Maybe go look at:</p>
<h1 class="font-heading-xl margin-y-0">404 Error - Page Not Found</h1>
<p>The page you are looking for could not be found. Please check the URL and try again.</p>
<p>You may want to visit:</p>
<ul class="usa-list">
<li><a href="{% url 'index' %}">homepage</a></li>
<li><a href="{% url 'nofos:nofo_index' %}">all nofos</a></li>
Expand Down
10 changes: 5 additions & 5 deletions bloom_nofos/bloom_nofos/templates/500.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% extends 'base.html' %}

{% block title %}
500 fam, yikes — Server error
500 - Server Error
{% endblock %}


{% block content %}
<h1 class="font-heading-xl margin-y-0">500 error, yikes</h1>
<p>Well dang, buckaroo, you’ve stumbled upon a brand new kinda trouble!</p>
<p>If you’re in a fix and want to report it, <a href="https://airtable.com/appdaa5AqUwI8jdOo/pagpyAKIEOyLofFCw/form" target="_blank">fill out a support ticket</a> and well be in touch about it pronto.</p>
<p>Why not mosey on back to:</p>
<h1 class="font-heading-xl margin-y-0">500 Error - Server Error</h1>
<p>Sorry, something went wrong on our end. Our team has been notified of this issue.</p>
<p>If you'd like to report this error, please <a href="https://airtable.com/appdaa5AqUwI8jdOo/pagpyAKIEOyLofFCw/form" target="_blank">submit a support ticket</a> and we'll investigate the issue.</p>
<p>You may want to visit:</p>
<ul class="usa-list">
<li><a href="{% url 'index' %}">homepage</a></li>
<li><a href="{% url 'nofos:nofo_index' %}">all nofos</a></li>
Expand Down
7 changes: 6 additions & 1 deletion bloom_nofos/nofos/nofo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from urllib.parse import parse_qs, urlparse

import cssutils
from django.forms import ValidationError
import markdown
import requests
from bs4 import BeautifulSoup, NavigableString, Tag
Expand Down Expand Up @@ -189,7 +190,11 @@ def create_nofo(title, sections):
nofo = Nofo(title=title)
nofo.number = "NOFO #999"
nofo.save()
return _build_nofo(nofo, sections)
try:
return _build_nofo(nofo, sections)
except ValidationError as e:
e.nofo = nofo
raise e


def overwrite_nofo(nofo, sections):
Expand Down
14 changes: 11 additions & 3 deletions bloom_nofos/nofos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,24 @@ def nofo_import(request, pk=None):
if "html_id" in e.message_dict and any(
"characters" in msg for msg in e.message_dict["html_id"]
):
# Get the last successfully created subsection
last_subsection = (
Subsection.objects.filter(section__nofo=e.nofo)
.order_by("-order")
.first()
)
# TODO: dynamically pull in heading character limit from models.py _or_ error message
return render(
request,
"400.html",
status=422,
context={
"error_message_html": (
"<p>This document contains a heading that is too long.</p>"
f'<p>Your document ("<a href="/nofos/{e.nofo.id}/edit">{e.nofo.short_name or e.nofo.title}</a>") '
"contains a heading that is too long. Headings have a character limit of 511 characters.</p>"
"<p>This usually means that a paragraph has been incorrectly styled as a heading. "
"Please check your document's heading styles and try again.</p>"
"<p>Headings have a character limit of 511 characters</p>"
f'The last valid heading was "{last_subsection.name if last_subsection else "none"}", '
"so the incorrectly tagged paragraph is most likely after this heading.</p>"
),
"status": 422,
},
Expand Down

0 comments on commit ab8c53d

Please sign in to comment.