Skip to content

Commit 25eb0ce

Browse files
committed
feat: export CacheXError, BackendNotFoundError and RequestNotFoundError
@cache and the proxies raise these exceptions, but unlike every session and state exception they were only importable from fastapi_cachex.exceptions. Re-export them from the package next to LockTimeoutError. Closes #160
1 parent 9c59dcf commit 25eb0ce

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎fastapi_cachex/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from .dependencies import CacheBackend as CacheBackend
1212
from .dependencies import get_app_cache as get_app_cache
1313
from .dependencies import get_cache_backend as get_cache_backend
14+
from .exceptions import BackendNotFoundError as BackendNotFoundError
15+
from .exceptions import CacheXError as CacheXError
1416
from .exceptions import LockTimeoutError as LockTimeoutError
17+
from .exceptions import RequestNotFoundError as RequestNotFoundError
1518
from .lock import CacheLock as CacheLock
1619
from .manager import CacheManager as CacheManager
1720
from .manager_proxy import CacheManagerProxy as CacheManagerProxy
@@ -68,15 +71,18 @@ def _read_version() -> str:
6871

6972
__all__ = [
7073
"AppCache",
74+
"BackendNotFoundError",
7175
"BackendProxy",
7276
"CacheBackend",
7377
"CacheKeyBuilder",
7478
"CacheLock",
7579
"CacheManager",
7680
"CacheManagerProxy",
81+
"CacheXError",
7782
"FastAPICacheXSessionMiddleware",
7883
"InvalidStateError",
7984
"LockTimeoutError",
85+
"RequestNotFoundError",
8086
"Session",
8187
"SessionConfig",
8288
"SessionError",

‎tests/test_exports.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Exceptions raised by the core are importable from the package (#160)."""
2+
3+
import pytest
4+
5+
import fastapi_cachex
6+
from fastapi_cachex import exceptions
7+
8+
9+
@pytest.mark.parametrize(
10+
"name", ["BackendNotFoundError", "CacheXError", "RequestNotFoundError"]
11+
)
12+
def test_core_exception_is_exported(name: str) -> None:
13+
assert name in fastapi_cachex.__all__
14+
assert getattr(fastapi_cachex, name) is getattr(exceptions, name)

0 commit comments

Comments
 (0)