Exception: Fizzy::Error

Inherits:
StandardError
  • Object
show all
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.

Examples:

Catching errors

begin
  client.boards.list
rescue Fizzy::Error => e
  puts "#{e.code}: #{e.message}"
  puts "Hint: #{e.hint}" if e.hint
  exit e.exit_code
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • code (String)

    error category code

  • message (String)

    error message

  • hint (String, nil) (defaults to: nil)

    user-friendly hint

  • http_status (Integer, nil) (defaults to: nil)

    HTTP status code

  • retryable (Boolean) (defaults to: false)

    whether operation can be retried

  • retry_after (Integer, nil) (defaults to: nil)

    seconds to wait before retry

  • request_id (String, nil) (defaults to: nil)

    X-Request-Id from response

  • cause (Exception, nil) (defaults to: nil)

    underlying cause



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(message)
  @code = code
  @hint = hint
  @http_status = http_status
  @retryable = retryable
  @retry_after = retry_after
  @request_id = request_id
  @cause = cause
end

Instance Attribute Details

#causeException? (readonly)

Returns original error that caused this error.

Returns:

  • (Exception, nil)

    original error that caused this error



65
66
67
# File 'lib/fizzy/errors.rb', line 65

def cause
  @cause
end

#codeString (readonly)

Returns error category code.

Returns:

  • (String)

    error category code



47
48
49
# File 'lib/fizzy/errors.rb', line 47

def code
  @code
end

#hintString? (readonly)

Returns user-friendly hint for resolving the error.

Returns:

  • (String, nil)

    user-friendly hint for resolving the error



50
51
52
# File 'lib/fizzy/errors.rb', line 50

def hint
  @hint
end

#http_statusInteger? (readonly)

Returns HTTP status code that caused the error.

Returns:

  • (Integer, nil)

    HTTP status code that caused the error



53
54
55
# File 'lib/fizzy/errors.rb', line 53

def http_status
  @http_status
end

#request_idString? (readonly)

Returns X-Request-Id from the response.

Returns:

  • (String, nil)

    X-Request-Id from the response



62
63
64
# File 'lib/fizzy/errors.rb', line 62

def request_id
  @request_id
end

#retry_afterInteger? (readonly)

Returns seconds to wait before retrying (for rate limits).

Returns:

  • (Integer, nil)

    seconds to wait before retrying (for rate limits)



59
60
61
# File 'lib/fizzy/errors.rb', line 59

def retry_after
  @retry_after
end

#retryableBoolean (readonly)

Returns whether the operation can be retried.

Returns:

  • (Boolean)

    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.

Parameters:

  • code (String)

Returns:

  • (Integer)


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_codeInteger

Returns the exit code for CLI applications.

Returns:

  • (Integer)


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.

Returns:

  • (Boolean)


94
95
96
# File 'lib/fizzy/errors.rb', line 94

def retryable?
  @retryable
end