Skip to content

bugs? search scripts just catch httpx.HTTPStatusError #104

Description

@m-dmupba

A bunch of the search scripts just catch httpx.HTTPStatusError, wrap it into a generic Exception, and then only send str(e) back. That means they throw away the response body. And on most of these APIs (PubMed / Semantic Scholar / GitHub) the response body is basically where the real “what went wrong” explanation is.

Details

For example in skills/sn-search-academic/scripts/pubmed_search.py:160:

except Exception as e:
    print_json(make_result(False, args.query, "pubmed", [], str(e)))
    sys.exit(1)

For an HTTPStatusError, str(e) usually looks like:

Client error '422 Unprocessable Entity' for url '...'

Okay, that part is helpful. But it still drops resp.text. With GitHub, resp.text is often something like:

{"message": "Validation Failed", "errors": [...]}

That’s the part you actually want to debug.

Instead, add a tiny helper in search_utils.py to keep the response body when it exists:

def format_error(e: Exception) -> str:
    if isinstance(e, httpx.HTTPStatusError):
        body = e.response.text[:500] if e.response is not None else ""
        return f"{e}: {body}"
    return str(e)

Then every script’s except block can just use the same formatting, and you don’t lose the useful error details.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions