Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema: Add error checking on remote schema files #400

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions flattentool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,29 @@ def __init__(
)
if schema_filename:
if schema_filename.startswith("http"):
import json

import requests

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