[client] Unify status→exception mapping: _api_error (401 only) vs _post_authent (401+403) #187
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The status→exception mapping is encoded in two places with different rules:
_api_error(_core.py:46-47): 401 →ComwattAuthError, everything else →ComwattAPIError;_post_authent(_core.py:70-71): (401, 403) →ComwattAuthError.The asymmetry is arguably intentional (403 means "bad credentials" only on the auth endpoint; a 403 on a resource is an authorization failure, not an auth failure), but nothing states that, and any future third site (e.g. the WS handshake error path) will have to guess.
Fix: extract one helper (e.g.
_error_class(status_code, *, auth_context)) used by both sites, with a self-explanatory signature encoding the 403 nuance — or at minimum document the asymmetry at both sites.Done when: single mapping site (or documented asymmetry),
pytest -qgreen,tests/test_exceptions.pystill pins both behaviors.