Skip to content

Commit

Permalink
views.py: More specific JSON parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Oct 22, 2024
1 parent 35d6ea0 commit a57cfda
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions libcoveweb2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,31 @@ 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."),
"msg": f"There was an error. {supplied_data.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."),
"msg": f"There was an error. {supplied_data.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 a57cfda

Please sign in to comment.