Skip to content

Commit 01e8e09

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 01e8e09

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

flattentool/schema.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,29 @@ def __init__(
147147
)
148148
if schema_filename:
149149
if schema_filename.startswith("http"):
150+
import json
151+
150152
import requests
151153

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

0 commit comments

Comments
 (0)