Closed as not planned
Description
Background
No try catch on request call causing unhandled exception which can cause application error. See image below for server log on remote resolve error occurrence. In this case, one of ref API returns HTTP 502 on JSON Schema $ref resolve process
Proposal to Resolve
Looking at piece of code from this library on https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/validators.py#L975
try:
import requests
except ImportError:
requests = None
scheme = urlsplit(uri).scheme
if scheme in self.handlers:
result = self.handlers[scheme](uri)
elif scheme in ["http", "https"] and requests:
# Requests has support for detecting the correct encoding of
# json over http
result = requests.get(uri).json()
else:
# Otherwise, pass off to urllib and assume utf-8
with urlopen(uri) as url:
result = json.loads(url.read().decode("utf-8"))
if self.cache_remote:
self.store[uri] = result
return result
Try/Catch should be wrapping this part of code
result = requests.get(uri).json()
to ensure that error on request (e.g. 5xx HTTP response) can be handled gracefully.
If this is OK, I'd be glad to open PR for fix
Metadata
Metadata
Assignees
Labels
No labels