Skip to content

Commit 51af44e

Browse files
authored
feat: cleanup exceptions to avoid duplication (#153)
1 parent 0267b5b commit 51af44e

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

yalexs/api_async.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242
from .const import DEFAULT_BRAND
4343
from .doorbell import Doorbell, DoorbellDetail
44-
from .exceptions import AugustApiAIOHTTPError
44+
from .exceptions import AugustApiAIOHTTPError, YaleApiError, InvalidAuth
4545
from .lock import (
4646
Lock,
4747
LockDetail,
@@ -460,24 +460,24 @@ def _raise_response_exceptions(response: ClientResponse) -> None:
460460
response.raise_for_status()
461461
except ClientResponseError as err:
462462
if err.status in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
463-
raise AugustApiAIOHTTPError(
463+
raise InvalidAuth(
464464
f"Authentication failed: Verify brand is correct: {err.message}", err
465465
) from err
466466
if err.status == 422:
467-
raise AugustApiAIOHTTPError(
467+
raise YaleApiError(
468468
f"The operation failed because the bridge (connect) is offline: {err.message}",
469469
err,
470470
) from err
471471
if err.status == 423:
472-
raise AugustApiAIOHTTPError(
472+
raise YaleApiError(
473473
f"The operation failed because the bridge (connect) is in use: {err.message}",
474474
err,
475475
) from err
476476
if err.status == 408:
477-
raise AugustApiAIOHTTPError(
477+
raise YaleApiError(
478478
f"The operation timed out because the bridge (connect) failed to respond: {err.message}",
479479
err,
480480
) from err
481-
raise AugustApiAIOHTTPError(
481+
raise YaleApiError(
482482
f"The operation failed with error code {err.status}: {err.message}.", err
483483
) from err

yalexs/exceptions.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from http import HTTPStatus
44

55
from aiohttp import ClientError, ClientResponseError
6-
from requests.exceptions import HTTPError
76

87

98
class AugustApiAIOHTTPError(Exception):
@@ -22,9 +21,25 @@ def __init__(self, message: str, aiohttp_client_error: ClientError) -> None:
2221
)
2322

2423

25-
class AugustApiHTTPError(HTTPError):
24+
class YaleApiError(AugustApiAIOHTTPError):
2625
"""An yale access api error with a friendly user consumable string."""
2726

2827

28+
class RequireValidation(Exception):
29+
"""Error to indicate we require validation (2fa)."""
30+
31+
32+
class CannotConnect(YaleApiError):
33+
"""Error to indicate we cannot connect."""
34+
35+
36+
class InvalidAuth(YaleApiError):
37+
"""Error to indicate there is invalid auth."""
38+
39+
40+
class YaleXSError(Exception):
41+
"""Base error."""
42+
43+
2944
class ContentTokenExpired(Exception):
3045
"""Token required for accessing this resource is not valid."""

yalexs/manager/exceptions.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
from __future__ import annotations
44

5-
6-
class RequireValidation(Exception):
7-
"""Error to indicate we require validation (2fa)."""
8-
9-
10-
class CannotConnect(Exception):
11-
"""Error to indicate we cannot connect."""
12-
13-
14-
class InvalidAuth(Exception):
15-
"""Error to indicate there is invalid auth."""
16-
17-
18-
class YaleXSError(Exception):
19-
"""Base error."""
5+
from ..exceptions import ( # noqa: F401
6+
YaleApiError,
7+
RequireValidation,
8+
CannotConnect,
9+
InvalidAuth,
10+
YaleXSError,
11+
)

0 commit comments

Comments
 (0)