Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit 52d6a60

Browse files
authored
Add SonarrResourceNotFound Exception (#13)
* add SonarrResourceNotFound exception * Update __init__.py * Update client.py * Update test_client.py * Update client.py * Update client.py * Update client.py
1 parent 36d9a30 commit 52d6a60

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

sonarr/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
SonarrAccessRestricted,
44
SonarrConnectionError,
55
SonarrError,
6+
SonarrResourceNotFound,
67
)
78
from .sonarr import Client, Sonarr # noqa

sonarr/client.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
from yarl import URL
1010

1111
from .__version__ import __version__
12-
from .exceptions import SonarrAccessRestricted, SonarrConnectionError, SonarrError
12+
from .exceptions import (
13+
SonarrAccessRestricted,
14+
SonarrConnectionError,
15+
SonarrError,
16+
SonarrResourceNotFound,
17+
)
1318

1419

1520
class Client:
@@ -94,6 +99,9 @@ async def _request(
9499
"Access restricted. Please ensure valid API Key is provided", {}
95100
)
96101

102+
if response.status == 404:
103+
raise SonarrResourceNotFound("Resource not found")
104+
97105
content_type = response.headers.get("Content-Type", "")
98106

99107
if (response.status // 100) in [4, 5]:

sonarr/exceptions.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ class SonarrConnectionError(SonarrError):
1414

1515

1616
class SonarrAccessRestricted(SonarrError):
17-
"""Sonarr access restricted."""
17+
"""Sonarr access restricted exception."""
18+
19+
pass
20+
21+
22+
class SonarrResourceNotFound(SonarrError):
23+
"""Sonarr resource not found exception."""
1824

1925
pass

tests/test_client.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import pytest
55
from aiohttp import ClientSession
66
from sonarr import Client
7-
from sonarr.exceptions import SonarrAccessRestricted, SonarrConnectionError, SonarrError
7+
from sonarr.exceptions import (
8+
SonarrAccessRestricted,
9+
SonarrConnectionError,
10+
SonarrError,
11+
SonarrResourceNotFound,
12+
)
813

914
API_KEY = "MOCK_API_KEY"
1015
HOST = "192.168.1.89"
@@ -169,7 +174,7 @@ async def test_http_error404(aresponses):
169174

170175
async with ClientSession() as session:
171176
client = Client(HOST, API_KEY, session=session)
172-
with pytest.raises(SonarrError):
177+
with pytest.raises(SonarrResourceNotFound):
173178
assert await client._request("system/status")
174179

175180

0 commit comments

Comments
 (0)