Skip to content

Commit

Permalink
Merge pull request #9 from DARPA-ASKEM/error-fix
Browse files Browse the repository at this point in the history
better error handling for node failure
  • Loading branch information
satchelbaldwin authored Mar 27, 2024
2 parents 6471eea + c43a9cc commit 222bc29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/search/providers/esgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,12 @@ def run_esgf_query(

full_url = f"{default_settings.esgf_url}/search?{encoded_string}"
r = requests.get(full_url)
response = r.json()
if r.status_code != 200:
error = str(r.content)
raise ConnectionError(
f"Failed to search against ESGF node: {full_url} {r.status_code} {response}"
f"Failed to search against ESGF node: {full_url}: error from node upstream is: {r.status_code} {error}"
)
response = r.json()

# parallel over datasets, but delay fetching url until needed
return dask.compute(
Expand Down
5 changes: 4 additions & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ async def job_status(job_id: str, redis=Depends(get_redis)):

@app.get("/search/esgf")
async def esgf_search(query: str = "", page: int = 1, refresh_cache=False):
datasets = esgf.search(query, page, refresh_cache)
try:
datasets = esgf.search(query, page, refresh_cache)
except Exception as e:
return {"error": f"failed to fetch datasets: {e}"}
return {"results": datasets}


Expand Down

0 comments on commit 222bc29

Please sign in to comment.