Skip to content

Add centralized request error handling to base client class #70

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

Merged
merged 8 commits into from
Jul 8, 2025

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jul 8, 2025

This PR centralises request handling into the base class, to allow for much cleaner error reporting. It also refactors tests to use respx_mock as a fixture, and adds several new tests for awkward cases.

Closes #69

ml-evs and others added 2 commits July 8, 2025 12:48
Replace manual error handling in all HTTP request methods with calls to
centralized _get(), _post(), and _put() methods from the base class.

Changes:
- Remove repetitive status code and JSON status checks
- Use _get() for GET requests: get_info, get_block_info, get_items,
  search_items, get_item, get_collection
- Use _post() for POST requests: create_item, update_item, get_block,
  upload_file, create_data_block, _update_data_block
- Use _put() for PUT requests: create_collection
- Maintain existing custom error handling for authenticate() method
- Significantly reduce code duplication and improve maintainability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ml-evs ml-evs force-pushed the ml-evs/show-errors branch from 977fc4b to 61095be Compare July 8, 2025 11:48
ml-evs and others added 2 commits July 8, 2025 12:54
- 401/403: Authentication guidance with API key setup instructions
- 404: Helpful message about checking URL/endpoint correctness
- 429: Rate limiting guidance
- 500: Server bug reporting with server version info
- 502: Gateway connectivity issues
- 503: Service unavailable with deployment issue reporting
- 504: Gateway timeout guidance
- Show response content for JSON parsing errors on successful responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ml-evs ml-evs force-pushed the ml-evs/show-errors branch from 61095be to ece3090 Compare July 8, 2025 11:57
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 55.42169% with 37 lines in your changes missing coverage. Please review.

Project coverage is 42.97%. Comparing base (7f7365c) to head (df0db32).

Files with missing lines Patch % Lines
src/datalab_api/_base.py 57.89% 24 Missing ⚠️
src/datalab_api/__init__.py 50.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
+ Coverage   37.01%   42.97%   +5.95%     
==========================================
  Files           5        5              
  Lines         489      491       +2     
==========================================
+ Hits          181      211      +30     
+ Misses        308      280      -28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ml-evs ml-evs marked this pull request as ready for review July 8, 2025 13:51
@ml-evs ml-evs added the enhancement New feature or request label Jul 8, 2025
@ml-evs ml-evs merged commit 3061651 into main Jul 8, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show server errors more readily
1 participant