Skip to content

API client to throw error instead of None #820

Closed

Description

@inimaz

The Api client should raise_for_status() instead of None if there is an error. Like this we can call the API client and give a more meaningful error to the user.

Things to consider:

  • The API client should throw but the emissionsTracker should not break, this means that we should try-catch in the emissions tracker.
  • One should check as well if in any of the responses we are if response is None because now they will throw the error

Originally posted by @inimaz in #798 (comment)

Activity

  1. added
    good first issue
    enhancement
    on Apr 14, 2025
  2. bcmyguest commented on Jun 29, 2025

    @bcmyguest

    Would be happy to take this one if it's still relevant :)

  3. bcmyguest commented on Jun 29, 2025

    @bcmyguest

    Noticed a couple of other things when trying to get env setup.

    • project could benefit from using uv for dependency resolution (on install and pip compile)

    eg. (not sure this is complete, more info here

    # pyproject.toml
    
    [tool.hatch.envs.default]
    # pip-compile automate the export of environments.txt
    type = "pip-compile"
    installer = "uv"
    pip-compile-resolver = "uv"
    
    • python3.8 tests do not work as installing urllib==2.5.0 is not possible on py3.8
    • test deps don't seem to be separated from build deps
    • setting CODECARBON_ALLOW_MULTIPLE_RUNS env variable could be done with pytest-dotenv setting in pytest.ini and adding a .env.test file

    All except the second one are somewhat debatable, so not sure the best place to put them - happy to elaborate.

  4. inimaz commented on Jun 30, 2025

    @inimaz
    CollaboratorAuthor

    Hello @bcmyguest It is still relevant! Feel free to take it/ask for any questions.

    • About the use of uv, I agree. I see @benoit-cty already started a branch to migrate maybe it can be discussed in that PR?
    • About test deps not separated from build deps. I think this is only true for the env api. Thanks for pointing out. We use it to deploy our API, we could separate it into api-test and api.
    • And about the pytest.ini, indeed go ahead!
  5. benoit-cty commented on Jul 1, 2025

    @benoit-cty
    Contributor

    Hello,
    Yes, we would like to switch to UV. I stopped my PR has I don't know how to migrate some part, which I do not write done :-(. I can do the rebase tomorrow and check what is left to do.

    Thanks for contributing !

  6. benoit-cty commented on Jul 2, 2025

    @benoit-cty
    Contributor

    Hello @bcmyguest I've made the rebase if you want to have a look at #815

  7. sankalpsthakur commented on Jul 27, 2026

    @sankalpsthakur
    Contributor

    I'd like to take this — will make the API client raise on HTTP errors and catch in the emissions tracker.

  8. added a commit that references this issue on Jul 28, 2026
    2b43f3a
  9. added a commit that references this issue on Aug 3, 2026
    af78bb6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions