Exception: Basecamp::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Basecamp::Error
- Defined in:
- lib/basecamp/error.rb
Overview
Base error class for all Basecamp SDK errors. Provides structured error handling with codes, hints, and CLI exit codes.
Direct Known Subclasses
AmbiguousError, ApiError, 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.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/basecamp/error.rb', line 45 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.
35 36 37 |
# File 'lib/basecamp/error.rb', line 35 def cause @cause end |
#code ⇒ String (readonly)
Returns error category code.
17 18 19 |
# File 'lib/basecamp/error.rb', line 17 def code @code end |
#hint ⇒ String? (readonly)
Returns user-friendly hint for resolving the error.
20 21 22 |
# File 'lib/basecamp/error.rb', line 20 def hint @hint end |
#http_status ⇒ Integer? (readonly)
Returns HTTP status code that caused the error.
23 24 25 |
# File 'lib/basecamp/error.rb', line 23 def http_status @http_status end |
#request_id ⇒ String? (readonly)
Returns X-Request-Id from the response.
32 33 34 |
# File 'lib/basecamp/error.rb', line 32 def request_id @request_id end |
#retry_after ⇒ Integer? (readonly)
Returns seconds to wait before retrying (for rate limits).
29 30 31 |
# File 'lib/basecamp/error.rb', line 29 def retry_after @retry_after end |
#retryable ⇒ Boolean (readonly)
Returns whether the operation can be retried.
26 27 28 |
# File 'lib/basecamp/error.rb', line 26 def retryable @retryable end |
Class Method Details
.exit_code_for(code) ⇒ Integer
Maps error codes to exit codes.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/basecamp/error.rb', line 71 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.
58 59 60 |
# File 'lib/basecamp/error.rb', line 58 def exit_code self.class.exit_code_for(@code) end |
#retryable? ⇒ Boolean
Returns whether this error can be retried.
64 65 66 |
# File 'lib/basecamp/error.rb', line 64 def retryable? @retryable end |