Coverage for netrun_errors / __init__.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-12-15 18:14 +0000

1""" 

2Netrun Unified Error Handling Package. 

3 

4A comprehensive error handling library for FastAPI applications with: 

5- Structured JSON error responses 

6- Automatic correlation ID generation (integrates with netrun-logging if available) 

7- Machine-readable error codes 

8- Global exception handlers 

9- Request/response logging middleware 

10 

11Version: 1.1.0 

12Author: Netrun Systems 

13License: MIT 

14 

15v1.1.0 Changes: 

16- Added netrun-logging integration for correlation ID consistency 

17- Added RateLimitExceededError (HTTP 429) 

18- Added BadGatewayError (HTTP 502) 

19- Added GatewayTimeoutError (HTTP 504) 

20- Added ExternalServiceError for generic external API failures 

21- Updated handlers to use netrun-logging when available 

22""" 

23 

24__version__ = "1.1.0" 

25 

26# Base exception 

27from .base import NetrunException 

28 

29# Authentication exceptions 

30from .auth import ( 

31 AuthenticationRequiredError, 

32 InvalidCredentialsError, 

33 TokenExpiredError, 

34 TokenInvalidError, 

35 TokenRevokedError, 

36) 

37 

38# Authorization exceptions 

39from .authorization import InsufficientPermissionsError, TenantAccessDeniedError 

40 

41# Resource exceptions 

42from .resource import ResourceConflictError, ResourceNotFoundError 

43 

44# Service exceptions 

45from .service import ( 

46 ServiceUnavailableError, 

47 TemporalUnavailableError, 

48 RateLimitExceededError, 

49 BadGatewayError, 

50 GatewayTimeoutError, 

51 ExternalServiceError, 

52) 

53 

54# Exception handlers 

55from .handlers import install_exception_handlers 

56 

57# Middleware 

58from .middleware import install_error_logging_middleware 

59 

60__all__ = [ 

61 # Base 

62 "NetrunException", 

63 # Authentication 

64 "InvalidCredentialsError", 

65 "TokenExpiredError", 

66 "TokenInvalidError", 

67 "TokenRevokedError", 

68 "AuthenticationRequiredError", 

69 # Authorization 

70 "InsufficientPermissionsError", 

71 "TenantAccessDeniedError", 

72 # Resource 

73 "ResourceNotFoundError", 

74 "ResourceConflictError", 

75 # Service 

76 "ServiceUnavailableError", 

77 "TemporalUnavailableError", 

78 "RateLimitExceededError", 

79 "BadGatewayError", 

80 "GatewayTimeoutError", 

81 "ExternalServiceError", 

82 # Handlers 

83 "install_exception_handlers", 

84 # Middleware 

85 "install_error_logging_middleware", 

86]