From 6538e4af5efb792ea2a49bfe06abc676dcc5831f Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 21 Nov 2022 19:51:14 -0700 Subject: [PATCH] Add `NotFoundError` as an exception type --- aiopurpleair/errors.py | 7 +++++++ tests/fixtures/error_not_found_response.json | 6 ++++++ tests/test_api.py | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/error_not_found_response.json diff --git a/aiopurpleair/errors.py b/aiopurpleair/errors.py index acac21d..c666720 100644 --- a/aiopurpleair/errors.py +++ b/aiopurpleair/errors.py @@ -13,6 +13,12 @@ class PurpleAirError(Exception): pass +class NotFoundError(PurpleAirError): + """Define an unknown resource.""" + + pass + + class InvalidRequestError(PurpleAirError): """Define an invalid request.""" @@ -34,6 +40,7 @@ class InvalidApiKeyError(RequestError): ERROR_CODE_MAP = { "ApiKeyMissingError": InvalidApiKeyError, "ApiKeyInvalidError": InvalidApiKeyError, + "NotFoundError": NotFoundError, } diff --git a/tests/fixtures/error_not_found_response.json b/tests/fixtures/error_not_found_response.json new file mode 100644 index 0000000..445f6d7 --- /dev/null +++ b/tests/fixtures/error_not_found_response.json @@ -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." +} diff --git a/tests/test_api.py b/tests/test_api.py index cff959b..05c2913 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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 @@ -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), ], )