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
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
1from __future__ import annotations
3from fastapi import status
5from litellm.proxy._types import ProxyErrorTypes, ProxyException
8class IdentityResolutionError(Exception):
9 """Base for every failure raised while resolving a caller's identity."""
12class NoDatabaseConnectionError(IdentityResolutionError):
13 def __init__(self) -> None:
14 super().__init__("No DB Connected. See - https://docs.litellm.ai/docs/proxy/virtual_keys")
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}.")
22class KeyNotFoundError(IdentityResolutionError, ProxyException):
23 """The token matched nothing in the cache or the verification token table.
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 """
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 )
39class PrincipalMissingSourceKeyError(IdentityResolutionError):
40 def __init__(self) -> None:
41 super().__init__("Principal carries no source key; it was not produced by IdentityStore.resolve")