Exception: ApolloDeploySignalSdkRails::SDKError
- Inherits:
-
StandardError
- Object
- StandardError
- ApolloDeploySignalSdkRails::SDKError
- Defined in:
- lib/apollo_deploy_signal_sdk_rails/errors.rb
Overview
Structured error raised on API and network failures.
Inherits from StandardError and provides structured access to error details including status code, error code, request ID, and convenience methods for common error classifications.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
Machine-readable error code (e.g. "not_found", "rate_limit_exceeded").
-
#details ⇒ Hash?
readonly
Structured error details.
-
#hint ⇒ String?
readonly
Helpful hint for resolving the error.
-
#method ⇒ String?
readonly
HTTP method that caused the error.
-
#path ⇒ String?
readonly
Request path that caused the error.
-
#request_id ⇒ String?
readonly
Unique request identifier from the server.
-
#status ⇒ Integer
readonly
HTTP status code (0 for network errors).
-
#timestamp ⇒ String?
readonly
ISO 8601 timestamp of error occurrence.
Instance Method Summary collapse
-
#auth_error? ⇒ Boolean
True if the error is authentication-related.
-
#client_error? ⇒ Boolean
True if status is 4xx (client error).
-
#forbidden? ⇒ Boolean
True if the error is a permission error (HTTP 403).
-
#initialize(message, status = 0, code = "unknown_error", request_id: nil, timestamp: nil, path: nil, method: nil, hint: nil, details: nil) ⇒ SDKError
constructor
Create a new SDKError.
-
#not_found? ⇒ Boolean
True if the resource was not found (HTTP 404).
-
#rate_limited? ⇒ Boolean
True if the error is a rate limit (HTTP 429).
-
#retryable? ⇒ Boolean
True if this error is safe to retry.
-
#server_error? ⇒ Boolean
True if status is 5xx (server error).
-
#to_h ⇒ Hash
A hash representation for logging and serialization.
-
#to_json(*args) ⇒ String
JSON representation for logging.
-
#validation_error? ⇒ Boolean
True if the error is a validation error.
Constructor Details
#initialize(message, status = 0, code = "unknown_error", request_id: nil, timestamp: nil, path: nil, method: nil, hint: nil, details: nil) ⇒ SDKError
Create a new SDKError.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 62 def initialize( , status = 0, code = "unknown_error", request_id: nil, timestamp: nil, path: nil, method: nil, hint: nil, details: nil ) super() @code = code @status = status @request_id = request_id @timestamp = @path = path @method = method @hint = hint @details = details end |
Instance Attribute Details
#code ⇒ String (readonly)
Returns machine-readable error code (e.g. "not_found", "rate_limit_exceeded").
28 29 30 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 28 def code @code end |
#details ⇒ Hash? (readonly)
Returns structured error details.
49 50 51 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 49 def details @details end |
#hint ⇒ String? (readonly)
Returns helpful hint for resolving the error.
46 47 48 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 46 def hint @hint end |
#method ⇒ String? (readonly)
Returns HTTP method that caused the error.
43 44 45 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 43 def method @method end |
#path ⇒ String? (readonly)
Returns request path that caused the error.
40 41 42 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 40 def path @path end |
#request_id ⇒ String? (readonly)
Returns unique request identifier from the server.
34 35 36 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 34 def request_id @request_id end |
#status ⇒ Integer (readonly)
Returns HTTP status code (0 for network errors).
31 32 33 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 31 def status @status end |
#timestamp ⇒ String? (readonly)
Returns ISO 8601 timestamp of error occurrence.
37 38 39 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 37 def @timestamp end |
Instance Method Details
#auth_error? ⇒ Boolean
Returns true if the error is authentication-related.
91 92 93 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 91 def auth_error? %w[unauthorized credential_expired credential_revoked].include?(@code) end |
#client_error? ⇒ Boolean
Returns true if status is 4xx (client error).
117 118 119 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 117 def client_error? @status >= 400 && @status < 500 end |
#forbidden? ⇒ Boolean
Returns true if the error is a permission error (HTTP 403).
96 97 98 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 96 def forbidden? @code == "forbidden" || @status == 403 end |
#not_found? ⇒ Boolean
Returns true if the resource was not found (HTTP 404).
101 102 103 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 101 def not_found? @code == "not_found" || @status == 404 end |
#rate_limited? ⇒ Boolean
Returns true if the error is a rate limit (HTTP 429).
86 87 88 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 86 def rate_limited? @code == "rate_limit_exceeded" || @status == 429 end |
#retryable? ⇒ Boolean
Returns true if this error is safe to retry.
122 123 124 125 126 127 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 122 def retryable? @code == "network_error" || @code == "gateway_timeout" || [408, 425, 429].include?(@status) || @status >= 500 end |
#server_error? ⇒ Boolean
Returns true if status is 5xx (server error).
112 113 114 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 112 def server_error? @status >= 500 end |
#to_h ⇒ Hash
Returns a hash representation for logging and serialization.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 130 def to_h { name: "SDKError", message: , status: @status, code: @code, request_id: @request_id, timestamp: @timestamp, path: @path, method: @method, hint: @hint, details: @details }.compact end |
#to_json(*args) ⇒ String
Returns JSON representation for logging.
146 147 148 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 146 def to_json(*args) to_h.to_json(*args) end |
#validation_error? ⇒ Boolean
Returns true if the error is a validation error.
106 107 108 109 |
# File 'lib/apollo_deploy_signal_sdk_rails/errors.rb', line 106 def validation_error? %w[validation_failed request_validation_failed bad_request unprocessable_entity].include?(@code) || @status == 422 end |