Exception: AppStoreServerApi::Error
- Inherits:
-
StandardError
- Object
- StandardError
- AppStoreServerApi::Error
- Defined in:
- lib/app_store_server_api/error.rb
Direct Known Subclasses
InvalidResponseError, InvalidTestNotificationTokenError, InvalidTransactionIdError, RateLimitExceededError, ServerError, ServerNotificationURLNotFoundError, TestNotificationNotFoundError, TransactionIdNotFoundError, UnauthorizedError
Defined Under Namespace
Classes: InvalidResponseError, InvalidTestNotificationTokenError, InvalidTransactionIdError, RateLimitExceededError, ServerError, ServerNotificationURLNotFoundError, TestNotificationNotFoundError, TransactionIdNotFoundError, UnauthorizedError
Constant Summary collapse
- ERROR_CODE_MAP =
map error code to error class
{ 4040010 => Error::TransactionIdNotFoundError, 4000020 => Error::InvalidTestNotificationTokenError, 4000006 => Error::InvalidTransactionIdError, 4290000 => Error::RateLimitExceededError, 4040007 => Error::ServerNotificationURLNotFoundError, 4040008 => Error::TestNotificationNotFoundError, }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.handle_error(response) ⇒ Object
raise error from response.
Instance Method Summary collapse
-
#initialize(code:, message:, response:) ⇒ Error
constructor
initialize error.
- #inspect ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(code:, message:, response:) ⇒ Error
initialize error
11 12 13 14 15 |
# File 'lib/app_store_server_api/error.rb', line 11 def initialize(code:, message:, response:) super() @code = code @response = response end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/app_store_server_api/error.rb', line 5 def code @code end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/app_store_server_api/error.rb', line 5 def response @response end |
Class Method Details
.handle_error(response) ⇒ Object
raise error from response
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/app_store_server_api/error.rb', line 83 def self.handle_error(response) case response.status when 401 # Unauthorized error # reasons: # - JWT in the authorization header is invalid. raise Error::.new(response: response) when 500 raise Error::ServerError.new(response: response) else data = JSON.parse(response.body) # error object must be {errorCode: Integer, errorMessage: String} unless data.has_key?('errorCode') && data.has_key?('errorMessage') raise Error::InvalidResponseError.new(message: 'response body is invalid', response: response) end error_code = data['errorCode'] error_class = ERROR_CODE_MAP[error_code] || Error raise error_class.new(code: error_code, message: data['errorMessage'], response: response) end end |
Instance Method Details
#inspect ⇒ Object
25 26 27 |
# File 'lib/app_store_server_api/error.rb', line 25 def inspect "#<#{self.class.name}: #{to_h.to_json}>" end |
#to_h ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/app_store_server_api/error.rb', line 17 def to_h { code: code, message: , response: response } end |