Skip to content

Commit

Permalink
schema: Add error checking on remote schema files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelwood committed Sep 20, 2022
1 parent b5619d6 commit f2709b1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions flattentool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,27 @@ def __init__(
if schema_filename:
if schema_filename.startswith("http"):
import requests
import json

r = requests.get(schema_filename)
self.root_schema_dict = jsonref.loads(
r.text, object_pairs_hook=OrderedDict
)

try:
r.raise_for_status()
except requests.HTTPError:
raise ValueError(
_(
"The URL provided for the schema in schema_filename was not accessible"
)
)

try:
self.root_schema_dict = jsonref.loads(
r.text, object_pairs_hook=OrderedDict
)
except json.JSONDecodeError:
raise ValueError(
_("The schema provided in schema_filename was not valid JSON")
)
else:
if disable_local_refs:
with codecs.open(schema_filename, encoding="utf-8") as schema_file:
Expand Down

0 comments on commit f2709b1

Please sign in to comment.