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 6c39872 commit 921263c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
12 changes: 6 additions & 6 deletions libcoveweb2/templatetags/cove_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def cove_modal_list(**kw):
@register.inclusion_tag("modal_errors.html")
def cove_modal_errors(**context):
if hasattr(settings, "VALIDATION_ERROR_LOCATIONS_LENGTH"):
context["validation_error_locations_length"] = (
settings.VALIDATION_ERROR_LOCATIONS_LENGTH
)
context[
"validation_error_locations_length"
] = settings.VALIDATION_ERROR_LOCATIONS_LENGTH
else:
context["validation_error_locations_length"] = 1000
if hasattr(settings, "VALIDATION_ERROR_LOCATIONS_SAMPLE"):
context["validation_error_locations_sample"] = (
settings.VALIDATION_ERROR_LOCATIONS_SAMPLE
)
context[
"validation_error_locations_sample"
] = settings.VALIDATION_ERROR_LOCATIONS_SAMPLE
return context


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 921263c

Please sign in to comment.