Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NotFoundError as an exception type #22

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aiopurpleair/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class PurpleAirError(Exception):
pass


class NotFoundError(PurpleAirError):
"""Define an unknown resource."""

pass


class InvalidRequestError(PurpleAirError):
"""Define an invalid request."""

Expand All @@ -34,6 +40,7 @@ class InvalidApiKeyError(RequestError):
ERROR_CODE_MAP = {
"ApiKeyMissingError": InvalidApiKeyError,
"ApiKeyInvalidError": InvalidApiKeyError,
"NotFoundError": NotFoundError,
}


Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/error_not_found_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"api_version": "V1.0.11-0.0.41",
"time_stamp": 1669085063,
"error": "NotFoundError",
"description": "Cannot find a sensor with the provided parameters."
}
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from aresponses import ResponsesMockServer

from aiopurpleair import API
from aiopurpleair.errors import InvalidApiKeyError, RequestError
from aiopurpleair.errors import InvalidApiKeyError, NotFoundError, RequestError
from aiopurpleair.models.keys import ApiKeyType, GetKeysResponse
from tests.common import TEST_API_KEY, load_fixture

Expand All @@ -20,6 +20,7 @@
[
("error_invalid_api_key_response.json", InvalidApiKeyError, 403),
("error_missing_api_key_response.json", InvalidApiKeyError, 403),
("error_not_found_response.json", NotFoundError, 404),
("error_unknown_response.json", RequestError, 500),
],
)
Expand Down