Skip to content

Commit c03eae0

Browse files
authored
Merge pull request #17 from OpenDataServices/json_parsing_error
Specific JSON parsing error
2 parents b103bfc + eead408 commit c03eae0

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
## Changed
1111

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

1415
## [0.3.0] - 2023-09-14
1516

libcoveweb2/views.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,33 @@ def view_does_not_exist(self, request):
149149

150150
def view_data_has_error(self, request, supplied_data):
151151
"""Called if the supplied data has any error set."""
152-
return render(
153-
request,
154-
self.error_template,
155-
{
156-
"sub_title": _("Sorry, there was an error."),
157-
"link": "index",
158-
"link_text": _("Go to Home page"),
159-
"msg": _("There was an error."),
160-
},
161-
status=500,
162-
)
152+
if supplied_data.error.startswith("JSON: Data parsing error"):
153+
return render(
154+
request,
155+
self.error_template,
156+
{
157+
"sub_title": _("Data parsing error."),
158+
"link": "index",
159+
"link_text": _("Go to Home page"),
160+
"msg": _(
161+
"The data is not valid JSON. "
162+
+ "Use a JSON validator tool to correct your data."
163+
),
164+
},
165+
status=500,
166+
)
167+
else:
168+
return render(
169+
request,
170+
self.error_template,
171+
{
172+
"sub_title": _("Sorry, there was an error."),
173+
"link": "index",
174+
"link_text": _("Go to Home page"),
175+
"msg": _("There was an error."),
176+
},
177+
status=500,
178+
)
163179

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

0 commit comments

Comments
 (0)