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

[ENG-6896] Project overview not loading if GV is down #10913

Merged
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
30 changes: 22 additions & 8 deletions osf/external/gravy_valet/request_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import auth_helpers
import requests
from requests.exceptions import RequestException

from website import settings

Expand Down Expand Up @@ -155,13 +156,16 @@ def get_gv_result(
params: dict = None,
): # -> JSONAPIResultEntry
'''Processes the result of a request to a GravyValet detail endpoint into a single JSONAPIResultEntry.'''
response_json = _make_gv_request(
response = _make_gv_request(
endpoint_url=endpoint_url,
requesting_user=requesting_user,
requested_resource=requested_resource,
request_method=request_method,
params=params,
).json()
)
if not response:
return
response_json = response.json()

if not response_json.get('data'):
return None
Expand All @@ -180,15 +184,18 @@ def get_raw_gv_result(
params: dict = None,
):
'''Processes the result of a request to a GravyValet detail endpoint into a single JSONAPIResultEntry.'''
response_json = _make_gv_request(
response = _make_gv_request(
endpoint_url=endpoint_url,
requesting_user=requesting_user,
requested_resource=requested_resource,
request_method=request_method,
params=params,
).json()
)
if not response:
return {}
response_json = response.json()
if not response_json.get('data'):
return dict()
return {}
return response_json['data']


Expand All @@ -200,13 +207,17 @@ def iterate_gv_results(
params: dict = None,
): # -> typing.Iterator[JSONAPIResultEntry]
'''Processes the result of a request to GravyValet list endpoint into a generator of JSONAPIResultEntires.'''
response_json = _make_gv_request(
response = _make_gv_request(
endpoint_url=endpoint_url,
requesting_user=requesting_user,
requested_resource=requested_resource,
request_method=request_method,
params=params
).json()
)
if not response:
return

response_json = response.json()
if not response_json.get('data'):
return # empty iterator
included_entities_lookup = _format_included_entities(response_json.get('included', []))
Expand All @@ -233,7 +244,10 @@ def _make_gv_request(
) | {'content-type': 'application/vnd.api+json'}
)
assert not (request_method == 'GET' and json_data is not None)
response = requests.request(url=endpoint_url, headers=auth_headers, params=params, method=request_method, json=json_data)
try:
response = requests.request(url=endpoint_url, headers=auth_headers, params=params, method=request_method, json=json_data)
except RequestException:
return None
if not response.ok:
# log error to Sentry
pass
Expand Down
Loading