diff --git a/oxrlib/loaders.py b/oxrlib/loaders.py index 95020c97e96216299555d48e08b95868d9f9fe8a..3e4d22b10d7f3b34c24399c30ba86356632d3c23 100644 --- a/oxrlib/loaders.py +++ b/oxrlib/loaders.py @@ -1,3 +1,19 @@ +class LoaderError(Exception): + pass + + +class LoaderNoDataError(LoaderError): + pass + + +class LoaderBadRequestError(LoaderError): + pass + + +class LoaderSourceError(LoaderError): + pass + + class FileCache: def __init__(self, dir_path, filename_pattern): self.dir_path = dir_path @@ -5,5 +21,7 @@ class FileCache: def historical(self, date, base): path = self.dir_path / self.pattern.format(date=date.isoformat(), base=base) - return path.open() - + try: + return path.open() + except FileNotFoundError as error: + raise LoaderNoDataError(path) from error diff --git a/tests/test_loaders.py b/tests/test_loaders.py index 841b56a4a48c4199f4fac1121ef4fbae53b086c8..76f20965be31b794df7e41e2ef27304c193a40f7 100644 --- a/tests/test_loaders.py +++ b/tests/test_loaders.py @@ -29,7 +29,7 @@ def test_cache_success(dummycache, date, base): def test_cache_not_found(dummycache, date, base): try: cache_file = dummycache.historical(date, base) - except FileNotFoundError: + except oxrlib.loaders.LoaderNoDataError: pass else: cache_file.close()