Coverage for src/ai_lls_lib/providers/exceptions.py: 100%

12 statements  

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

1"""Exception classes for verification providers.""" 

2 

3 

4class ProviderError(ValueError): 

5 """Raised when an upstream verification provider fails. 

6 

7 Extends ValueError for backward compatibility with existing 

8 error handlers. Carries an optional HTTP status code from the 

9 upstream response so callers can distinguish client errors from 

10 server/network failures. 

11 """ 

12 

13 def __init__(self, message: str, status_code: int | None = None): 

14 super().__init__(message) 

15 self.status_code = status_code 

16 

17 

18class ProviderFailureError(ProviderError): 

19 """Raised when bulk processing aborts because the provider failed for too many rows. 

20 

21 Distinct from a per-row ProviderError: this means the job as a whole could not be 

22 verified (total outage, bad credentials, exhausted quota, or a failure rate above the 

23 configured threshold) and must not be reported as completed. 

24 """ 

25 

26 def __init__(self, message: str, failures: int, attempted: int): 

27 super().__init__(message) 

28 self.failures = failures 

29 self.attempted = attempted 

30 

31 

32class ProviderQuotaError(ProviderError): 

33 """The provider rejected the call because the account balance or quota is exhausted. 

34 

35 Not retried and does not trip the circuit breaker: the vendor is up, the account is 

36 empty. Alarm on this separately from outages. 

37 """ 

38 

39 

40class ProviderAuthError(ProviderError): 

41 """The provider rejected the API key. Not retried; does not trip the circuit breaker.""" 

42 

43 

44class ProviderUnavailableError(ProviderError): 

45 """Raised without a network call while the circuit breaker is open."""