Skip to content

fix(api): raise HTTPError instead of returning None on API errors#1213

Open
MD-Mushfiqur123 wants to merge 2 commits into
mlco2:masterfrom
MD-Mushfiqur123:master
Open

fix(api): raise HTTPError instead of returning None on API errors#1213
MD-Mushfiqur123 wants to merge 2 commits into
mlco2:masterfrom
MD-Mushfiqur123:master

Conversation

@MD-Mushfiqur123

Copy link
Copy Markdown

Resolves #820

Changes:

  • Replaced _log_error() + return None pattern with r.raise_for_status() in all ApiClient methods
  • Removed unused _log_error method
  • Removed None-check in check_organization_exists (method now raises on HTTP errors)
  • add_emission and _create_run already have try/except wrappers so they continue to handle errors gracefully (logging + returning False/None)
  • CodeCarbonAPIOutput (used by EmissionsTracker) already wraps add_emission in try/except
  • Updated tests to expect requests.HTTPError instead of None returns

@MD-Mushfiqur123 MD-Mushfiqur123 requested a review from a team as a code owner May 28, 2026 01:43
@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.32%. Comparing base (987fbdf) to head (8fd5c58).

Files with missing lines Patch % Lines
codecarbon/core/api_client.py 53.84% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1213      +/-   ##
==========================================
+ Coverage   88.99%   89.32%   +0.33%     
==========================================
  Files          45       45              
  Lines        4316     4282      -34     
==========================================
- Hits         3841     3825      -16     
+ Misses        475      457      -18     

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@benoit-cty

Copy link
Copy Markdown
Contributor

Thanks for your contribution. Can you improve the test coverage ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API client to throw error instead of None

2 participants