cyberneticlibrary

Error handling pattern

2084-error-handling-pattern_364bc098skillsetup L14
tools-only/X-Skills
What it does

Structure exception hierarchies for specific error types

Best for

When structuring exception hierarchies for specific error types (auth, rate limit, policy, etc.)

Inputs
  • · API response codes and error messages
Outputs
  • · Exception classes with proper inheritance and payload handling
Preconditions
  • · HTTP status code mapping defined
  • · Error code taxonomy available
Failure modes
  • · Generic Exception used instead of specific subclass
  • · Error payload not extracted (retry_after in RateLimitError)
  • · HTTP error handler doesn't route all codes
  • · Custom exception doesn't inherit from base KlingAIError
Trust signals
  • · Specific exception classes for common API failure modes
  • · Payload capture (retry_after, message) in exception init
  • · HTTP status code routing in handle_api_error