Exception: SocialPlus::WebApi::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- SocialPlus::WebApi::ApiError
- Defined in:
- lib/social_plus/web_api/api_error.rb,
lib/social_plus/web_api/api_error.rb
Overview
An Exception class which wraps errors from SocialPlus Web API
Direct Known Subclasses
Constant Summary collapse
- EXCEPTION_CLASSES =
Hash.new(ApiError).tap do |exception_classes| exception_classes[4] = InvalidToken end
Instance Attribute Summary collapse
-
#code ⇒ Integer
readonly
The error code (API error code or HTTP status).
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(error) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(error) ⇒ ApiError
Returns a new instance of ApiError.
13 14 15 16 |
# File 'lib/social_plus/web_api/api_error.rb', line 13 def initialize(error) super(error['message']) @code = error['code'] end |
Instance Attribute Details
#code ⇒ Integer (readonly)
Returns the error code (API error code or HTTP status).
19 20 21 |
# File 'lib/social_plus/web_api/api_error.rb', line 19 def code @code end |
Class Method Details
.exception_from_api_result(response, result) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/social_plus/web_api/api_error.rb', line 30 def self.exception_from_api_result(response, result) if (response, result) error = result['error'] raise EXCEPTION_CLASSES[error['code']], error else raise HttpResponseError, response end end |