Skip to content

EntityNotFound should inherit from GetError #79

Description

@pederhan

It's incredibly unintuitive how to catch errors stemming from failed lookups in managers.py vs client.py. I've been burned many times now by trying to catch EntityNotFound, when the raised exception is actually GetError:

try:
    resp = some_method_that_interacts_with_api()
except EntityNotFound:
    # handle ...

EntityNotFound is not used at all in client.py - it is exclusively used in managers.py, and vice versa for GetError. This is a confusing dichotomy, when they are both some sort of GET request error, be it client-side or server-side.

Solution

All lookup-related exceptions should inherit from GetError so we can catch all lookup-related errors via GetError.

class EntityNotFound(GetError):

# ...

try:
    resp = some_method_that_interacts_with_api()
except GetError:
    # handle ...

Furthermore, after fixing this inheritance, we should consider explicitly raising EntityNotFound instead of GetError on 404 in client.py. Since EntityNotFound at that point inherits from GetError, we will not break consumers that expect GetError from 404 errors.

Activity

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

    enhancementNew feature or requestrefactorCode restructuring without functional changes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions