Coverage for health / utils / exceptions.py: 82%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-02 17:44 +0800

1""" 

2Custom exceptions for Garmin Health Sync system. 

3""" 

4 

5 

6class HealthSyncError(Exception): 

7 """Base exception for all health sync errors.""" 

8 

9 pass 

10 

11 

12class GarminAuthError(HealthSyncError): 

13 """Raised when Garmin authentication fails.""" 

14 

15 pass 

16 

17 

18class GarminAPIError(HealthSyncError): 

19 """Raised when Garmin API returns an error.""" 

20 

21 def __init__(self, message: str, status_code: int | None = None) -> None: 

22 """Initialize GarminAPIError. 

23 

24 Args: 

25 message: Error message 

26 status_code: HTTP status code if available 

27 """ 

28 super().__init__(message) 

29 self.status_code = status_code 

30 

31 

32class DataValidationError(HealthSyncError): 

33 """Raised when data validation fails.""" 

34 

35 pass 

36 

37 

38class StorageError(HealthSyncError): 

39 """Raised when file or database storage operations fail.""" 

40 

41 pass 

42 

43 

44class SyncError(HealthSyncError): 

45 """Raised when data synchronization fails.""" 

46 

47 pass 

48 

49 

50class RateLimitError(GarminAPIError): 

51 """Raised when API rate limit is exceeded.""" 

52 

53 def __init__(self, message: str = "API rate limit exceeded") -> None: 

54 """Initialize RateLimitError. 

55 

56 Args: 

57 message: Error message 

58 """ 

59 super().__init__(message, status_code=429)