Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific JSON parsing error #17

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading