Summary
When receiving a FailedToRetrieveItemException I have no clean programmatic way to know what was the underlying cause.
The message of the exception will provide an HTTP status code, but it is embedded in a full-text message and is more human-friendly than machine friendly.
Use cases
I would like to be able to route exceptions, e.g. to decide whether a failed attempt should be retried. A server-side (e.g. 5XX) error might be transient and is worth retrying, a client-side (e.g. 4XX) error is typically not.
Proposed solution
I can think of two main categories of solutions:
- Specific sub-exceptions, e.g.
AuhorizationException, AuthenticationException or InvalidRequestException.
- Add an additional property to the relevant exception(s), e.g.
FailedToRetrieveItemException.http_status.
Is there a workaround to accomplish this today?
I'm using a regex on the exception message to find and extract the HTTP status code.
References & Prior Work
N/A
Extra note
I also noticed that when timing out, an httpx.ConnectTimeout is raised. A OnePassword-SDK-defined exception, e.g. onepasswordconnectsdk.errors.TransportException would probably be cleaner.