Repository navigation
fix: include Zenodo API error response body in error messages (#169) - #181
rtmalikian wants to merge 5 commits into
Conversation
When a non-200 status code is returned from the Zenodo API, the error message now includes the response body (JSON or text) so users can diagnose the root cause (e.g., rate limiting, access denied, invalid record). Previously, only the status code was shown, making it impossible to debug intermittent 403/429 errors without using a browser. Fixes BrainLesion#169
There was a problem hiding this comment.
Pull request overview
This PR improves diagnosability of Zenodo download failures by surfacing Zenodo’s error response body in the raised ZenodoException, and extends test coverage to validate both JSON and plain-text error bodies.
Changes:
- Include Zenodo error response content (JSON or text fallback) in
_get_metadata_and_archive_url()exception messages. - Update the existing failure test to assert that JSON error details appear in the exception message.
- Add a new test covering the non-JSON (text body) fallback path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| brainles_preprocessing/utils/zenodo.py | Adds parsing of Zenodo error bodies and includes them in the raised exception message. |
| tests/test_zenodo.py | Expands assertions for error messages and adds a text-body fallback test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1. Catch ValueError only (requests.exceptions.JSONDecodeError is a subclass and may not exist in older requests versions) 2. Use status-code-aware error messages: 'Cannot find record' for 404, 'Failed to fetch record' for other status codes (403, 429, etc.)
|
Hi, I've addressed both Copilot review comments:
All 13 tests pass with the updated code. PR is ready for re-review. 🙏 |
|
looks solid, please fix the lint issues so we can approve and merge! Thanks for contributing @rtmalikian |
|
@rtmalikian friendly reminder ;) |
friendly reminder ;) |
There was a problem hiding this comment.
@rtmalikian please apply linting and resolve the merge conflict ;)
|
Thanks for the nudge! I looked into both items: Linting: black (the version pinned in pyproject) would reformat one spot in Merge conflict: I tried the merge against current main locally, and the only conflicting file is So merging this branch as-is would regress main back to the archive-URL path, and resolving just the test conflict would still leave that. I cannot push a merge commit or rebase the branch from here (no force-push), so before I do anything I wanted to check with you: would you prefer this PR closed as superseded by the files-API rewrite, or would you like me to port just the two tests (JSON-error and text-body cases) onto the new |
|
@MarcelRosier, how shall we move forward? |


Summary
When the Zenodo API returns a non-200 status code, the error response body (which contains the actual explanation from Zenodo) was being discarded. The error message only showed the status code, making it impossible to diagnose issues like rate limiting (429), access denied (403), or invalid records (404).
What was broken
In
_get_metadata_and_archive_url(), the error message was:This provided no information about why the request failed. Users had no way to distinguish between rate limiting, access restrictions, or invalid record IDs without manually visiting the URL in a browser.
What the fix does
Fixes #169
Verification
All 13 tests pass:
About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.
📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a
Disclosure: This code was developed with assistance from mimo-2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.