Skip to content

Commit ac024f5

Browse files
committed
Improve error handling in Owlery query function to differentiate between 400 Bad Request and other errors
1 parent f0f65de commit ac024f5

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

src/vfbquery/vfb_queries.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,19 +3087,37 @@ def _owlery_query_to_results(owl_query_string: str, short_form: str, return_data
30873087
owlery_url = f"{owlery_base}{endpoint}?{urlencode(params)}"
30883088

30893089
import sys
3090-
print(f"ERROR: Owlery {'instances' if query_instances else 'subclasses'} query failed: {e}", file=sys.stderr)
3091-
print(f" Full URL: {owlery_url}", file=sys.stderr)
3092-
print(f" Query string: {owl_query_string}", file=sys.stderr)
3093-
import traceback
3094-
traceback.print_exc()
3095-
# Return error indication with count=-1
3096-
if return_dataframe:
3097-
return pd.DataFrame()
3098-
return {
3099-
"headers": _get_standard_query_headers(),
3100-
"rows": [],
3101-
"count": -1
3102-
}
3090+
import requests
3091+
3092+
# Check if this is a 400 Bad Request (invalid query) vs other errors
3093+
is_bad_request = isinstance(e, requests.exceptions.HTTPError) and hasattr(e, 'response') and e.response.status_code == 400
3094+
3095+
if is_bad_request:
3096+
# 400 Bad Request means the term isn't valid for this type of query (e.g., anatomical query on expression pattern)
3097+
# Return 0 results instead of error
3098+
print(f"INFO: Owlery query returned 400 Bad Request (invalid for this term type): {owl_query_string}", file=sys.stderr)
3099+
if return_dataframe:
3100+
return pd.DataFrame()
3101+
return {
3102+
"headers": _get_standard_query_headers(),
3103+
"rows": [],
3104+
"count": 0
3105+
}
3106+
else:
3107+
# Other errors (500, network issues, etc.) - return error indication
3108+
print(f"ERROR: Owlery {'instances' if query_instances else 'subclasses'} query failed: {e}", file=sys.stderr)
3109+
print(f" Full URL: {owlery_url}", file=sys.stderr)
3110+
print(f" Query string: {owl_query_string}", file=sys.stderr)
3111+
import traceback
3112+
traceback.print_exc()
3113+
# Return error indication with count=-1
3114+
if return_dataframe:
3115+
return pd.DataFrame()
3116+
return {
3117+
"headers": _get_standard_query_headers(),
3118+
"rows": [],
3119+
"count": -1
3120+
}
31033121

31043122

31053123
def get_anatomy_scrnaseq(anatomy_short_form: str, return_dataframe=True, limit: int = -1):

0 commit comments

Comments
 (0)