Skip to content

Commit

Permalink
views.py: Specific JSON parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Dec 9, 2024
1 parent b103bfc commit eead408
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## Changed

- In `TaskWithState.process_get_state()` any changes to `process_data` are now ignored. https://github.com/OpenDataServices/lib-cove-web-2/issues/14
- Provide a specific error when JSON parsing fails, rather than generic "There was an error."

## [0.3.0] - 2023-09-14

Expand Down
38 changes: 27 additions & 11 deletions libcoveweb2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,33 @@ def view_does_not_exist(self, request):

def view_data_has_error(self, request, supplied_data):
"""Called if the supplied data has any error set."""
return render(
request,
self.error_template,
{
"sub_title": _("Sorry, there was an error."),
"link": "index",
"link_text": _("Go to Home page"),
"msg": _("There was an error."),
},
status=500,
)
if supplied_data.error.startswith("JSON: Data parsing error"):
return render(
request,
self.error_template,
{
"sub_title": _("Data parsing error."),
"link": "index",
"link_text": _("Go to Home page"),
"msg": _(
"The data is not valid JSON. "
+ "Use a JSON validator tool to correct your data."
),
},
status=500,
)
else:
return render(
request,
self.error_template,
{
"sub_title": _("Sorry, there was an error."),
"link": "index",
"link_text": _("Go to Home page"),
"msg": _("There was an error."),
},
status=500,
)

def view_has_expired(self, request, supplied_data):
"""Called if the data has expired and has now been deleted.
Expand Down

0 comments on commit eead408

Please sign in to comment.