Skip to content

Commit f2709b1

Browse files
committed
schema: Add error checking on remote schema files
When fetching and downloading we can get some obscure messages that are hard to distinguish between input data errors and configuration errors. (As seen with recent threesixtygiving test coves). This captures errors and rewords them to be more helpful.
1 parent b5619d6 commit f2709b1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

flattentool/schema.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,27 @@ def __init__(
148148
if schema_filename:
149149
if schema_filename.startswith("http"):
150150
import requests
151+
import json
151152

152153
r = requests.get(schema_filename)
153-
self.root_schema_dict = jsonref.loads(
154-
r.text, object_pairs_hook=OrderedDict
155-
)
154+
155+
try:
156+
r.raise_for_status()
157+
except requests.HTTPError:
158+
raise ValueError(
159+
_(
160+
"The URL provided for the schema in schema_filename was not accessible"
161+
)
162+
)
163+
164+
try:
165+
self.root_schema_dict = jsonref.loads(
166+
r.text, object_pairs_hook=OrderedDict
167+
)
168+
except json.JSONDecodeError:
169+
raise ValueError(
170+
_("The schema provided in schema_filename was not valid JSON")
171+
)
156172
else:
157173
if disable_local_refs:
158174
with codecs.open(schema_filename, encoding="utf-8") as schema_file:

0 commit comments

Comments
 (0)