Skip to content

Commit

Permalink
Improve error handling for client when updating provider list (#1222)
Browse files Browse the repository at this point in the history
* Improve error handling for client when updating provider list

* Pin griffe version for docs
  • Loading branch information
ml-evs committed Jun 30, 2022
1 parent 1a0fdc3 commit 7dbc5b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions optimade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"""

import json
from typing import List, Iterable

from pydantic import ValidationError
from optimade.models.links import LinksResource

PROVIDER_LIST_URLS = (
Expand Down Expand Up @@ -128,15 +130,21 @@ def get_child_database_links(
links_endp = base_url + "/v1/links"
try:
links = requests.get(links_endp, timeout=10)
except requests.ConnectionError as exc:
except (requests.ConnectionError, requests.Timeout) as exc:
raise RuntimeError(f"Unable to connect to provider {provider['id']}") from exc

if links.status_code != 200:
raise RuntimeError(
f"Invalid response from {links_endp} for provider {provider['id']}: {links.content}."
)

links = LinksResponse(**links.json())
try:
links = LinksResponse(**links.json())
except (ValidationError, json.JSONDecodeError) as exc:
raise RuntimeError(
f"Did not understand response from {provider['id']}: {links.content}"
) from exc

return [
link
for link in links.data
Expand Down
1 change: 1 addition & 0 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
griffe==0.21 # Currently mkdocstrings-python does not pin a griffe version, but it is quite flaky...
markupsafe==2.0.1 # Can be removed once aiida supports Jinja2>=3, see pallets/markupsafe#284
mike==1.1.2
mkdocs==1.3.0
Expand Down

0 comments on commit 7dbc5b7

Please sign in to comment.