Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/auth/resolvers/exceptions.py: 81%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:01 +0000

1from __future__ import annotations 

2 

3from fastapi import status 

4 

5from litellm.proxy._types import ProxyErrorTypes, ProxyException 

6 

7 

8class IdentityResolutionError(Exception): 

9 """Base for every failure raised while resolving a caller's identity.""" 

10 

11 

12class NoDatabaseConnectionError(IdentityResolutionError): 

13 def __init__(self) -> None: 

14 super().__init__("No DB Connected. See - https://docs.litellm.ai/docs/proxy/virtual_keys") 

15 

16 

17class KeyNotInCacheError(IdentityResolutionError): 

18 def __init__(self, hashed_token: str) -> None: 

19 super().__init__(f"Key doesn't exist in cache + check_cache_only=True. key={hashed_token}.") 

20 

21 

22class KeyNotFoundError(IdentityResolutionError, ProxyException): 

23 """The token matched nothing in the cache or the verification token table. 

24 

25 Also a ``ProxyException`` so the auth flow keeps mapping a missing key to the 

26 OpenAI 401 contract unchanged while callers migrate onto the typed hierarchy. 

27 """ 

28 

29 def __init__(self, hashed_token: str) -> None: 

30 ProxyException.__init__( 

31 self, 

32 message=f"Authentication Error, Invalid proxy server token passed. key={hashed_token}, not found in db. Create key via `/key/generate` call.", 

33 type=ProxyErrorTypes.token_not_found_in_db, 

34 param="key", 

35 code=status.HTTP_401_UNAUTHORIZED, 

36 ) 

37 

38 

39class PrincipalMissingSourceKeyError(IdentityResolutionError): 

40 def __init__(self) -> None: 

41 super().__init__("Principal carries no source key; it was not produced by IdentityStore.resolve")