Exception: Fizzy::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Fizzy::Error
- Defined in:
- lib/fizzy/errors.rb
Overview
Base error class for all Fizzy SDK errors. Provides structured error handling with codes, hints, and CLI exit codes.
Direct Known Subclasses
APIError, AmbiguousError, AuthError, ForbiddenError, NetworkError, NotFoundError, RateLimitError, UsageError, ValidationError
Instance Attribute Summary collapse
-
#cause ⇒ Exception?
readonly
Original error that caused this error.
-
#code ⇒ String
readonly
Error category code.
-
#hint ⇒ String?
readonly
User-friendly hint for resolving the error.
-
#http_status ⇒ Integer?
readonly
HTTP status code that caused the error.
-
#request_id ⇒ String?
readonly
X-Request-Id from the response.
-
#retry_after ⇒ Integer?
readonly
Seconds to wait before retrying (for rate limits).
-
#retryable ⇒ Boolean
readonly
Whether the operation can be retried.
Class Method Summary collapse
-
.exit_code_for(code) ⇒ Integer
Maps error codes to exit codes.
Instance Method Summary collapse
-
#exit_code ⇒ Integer
Returns the exit code for CLI applications.
-
#initialize(code:, message:, hint: nil, http_status: nil, retryable: false, retry_after: nil, request_id: nil, cause: nil) ⇒ Error
constructor
A new instance of Error.
-
#retryable? ⇒ Boolean
Returns whether this error can be retried.
Constructor Details
#initialize(code:, message:, hint: nil, http_status: nil, retryable: false, retry_after: nil, request_id: nil, cause: nil) ⇒ Error
Returns a new instance of Error.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fizzy/errors.rb', line 75 def initialize(code:, message:, hint: nil, http_status: nil, retryable: false, retry_after: nil, request_id: nil, cause: nil) super() @code = code @hint = hint @http_status = http_status @retryable = retryable @retry_after = retry_after @request_id = request_id @cause = cause end |
Instance Attribute Details
#cause ⇒ Exception? (readonly)
Returns original error that caused this error.
65 66 67 |
# File 'lib/fizzy/errors.rb', line 65 def cause @cause end |
#code ⇒ String (readonly)
Returns error category code.
47 48 49 |
# File 'lib/fizzy/errors.rb', line 47 def code @code end |
#hint ⇒ String? (readonly)
Returns user-friendly hint for resolving the error.
50 51 52 |
# File 'lib/fizzy/errors.rb', line 50 def hint @hint end |
#http_status ⇒ Integer? (readonly)
Returns HTTP status code that caused the error.
53 54 55 |
# File 'lib/fizzy/errors.rb', line 53 def http_status @http_status end |
#request_id ⇒ String? (readonly)
Returns X-Request-Id from the response.
62 63 64 |
# File 'lib/fizzy/errors.rb', line 62 def request_id @request_id end |
#retry_after ⇒ Integer? (readonly)
Returns seconds to wait before retrying (for rate limits).
59 60 61 |
# File 'lib/fizzy/errors.rb', line 59 def retry_after @retry_after end |
#retryable ⇒ Boolean (readonly)
Returns whether the operation can be retried.
56 57 58 |
# File 'lib/fizzy/errors.rb', line 56 def retryable @retryable end |
Class Method Details
.exit_code_for(code) ⇒ Integer
Maps error codes to exit codes.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fizzy/errors.rb', line 101 def self.exit_code_for(code) case code when ErrorCode::USAGE then ExitCode::USAGE when ErrorCode::NOT_FOUND then ExitCode::NOT_FOUND when ErrorCode::AUTH then ExitCode::AUTH when ErrorCode::FORBIDDEN then ExitCode::FORBIDDEN when ErrorCode::RATE_LIMIT then ExitCode::RATE_LIMIT when ErrorCode::NETWORK then ExitCode::NETWORK when ErrorCode::API then ExitCode::API when ErrorCode::AMBIGUOUS then ExitCode::AMBIGUOUS when ErrorCode::VALIDATION then ExitCode::VALIDATION else ExitCode::API end end |
Instance Method Details
#exit_code ⇒ Integer
Returns the exit code for CLI applications.
88 89 90 |
# File 'lib/fizzy/errors.rb', line 88 def exit_code self.class.exit_code_for(@code) end |
#retryable? ⇒ Boolean
Returns whether this error can be retried.
94 95 96 |
# File 'lib/fizzy/errors.rb', line 94 def retryable? @retryable end |