Skip to content

Commit

Permalink
show api error info on the front end
Browse files Browse the repository at this point in the history
  • Loading branch information
rachaelcodes committed May 20, 2024
1 parent 171203f commit 5c7a991
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django_app/redbox_app/redbox_core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def remove_doc_view(request, doc_id: uuid):
core_api.delete_file(file.core_file_uuid, request.user)
except HTTPError as e:
logger.error("Error deleting file object %s.", file, exc_info=e)
errors.append("failed to connect to core-api")
errors.append("There was an error deleting this file")

else:
logger.info("Removing document: %s", request.POST["doc_id"])
file.delete()
return redirect("documents")
return redirect("documents")

return render(
request,
Expand Down
18 changes: 18 additions & 0 deletions django_app/redbox_app/templates/macros/govuk-error-summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% macro govukErrorSummary(title="There is a problem", error_list=None, heading_level=2) %}
{% if error_list %}
<div class="govuk-error-summary" data-module="govuk-error-summary">
<div role="alert">
<h{{ heading_level }} class="govuk-error-summary__title">
{{ title }}
</h{{ heading_level }}>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list">
{% for error in error_list %}
<li>{{error}}</li>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endif %}
{% endmacro %}
3 changes: 3 additions & 0 deletions django_app/redbox_app/templates/remove-doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{% extends "base.html" %}
{% from "macros/govuk-button.html" import govukButton %}
{% from "macros/govuk-error-summary.html" import govukErrorSummary %}

{% block content %}

Expand All @@ -18,6 +19,8 @@

<h1 class="govuk-heading-m">Are you sure you want to remove this document?</h1>

{{ govukErrorSummary(error_list=errors) }}

<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Expand Down

0 comments on commit 5c7a991

Please sign in to comment.