Exception: Miasma::Error::ApiError
- Inherits:
-
Miasma::Error
- Object
- StandardError
- Miasma::Error
- Miasma::Error::ApiError
- Defined in:
- lib/miasma/error.rb
Overview
Api related errors
Direct Known Subclasses
Defined Under Namespace
Classes: AuthenticationError, RequestError
Instance Attribute Summary collapse
-
#response ⇒ HTTP::Response
readonly
Result of bad request.
-
#response_error_msg ⇒ String
readonly
Response error message.
Instance Method Summary collapse
-
#extract_error_message(response) ⇒ String, NilClass
Attempt to extract error message from response.
-
#initialize(msg, args = {}) ⇒ ApiError
constructor
Create new API error instance.
-
#message ⇒ String
Provides response error suffix.
Constructor Details
#initialize(msg, args = {}) ⇒ ApiError
Create new API error instance
29 30 31 32 33 34 |
# File 'lib/miasma/error.rb', line 29 def initialize(msg, args={}) super @response = args.to_smash[:response] @message = msg (@response) end |
Instance Attribute Details
#response ⇒ HTTP::Response (readonly)
Returns result of bad request.
20 21 22 |
# File 'lib/miasma/error.rb', line 20 def response @response end |
#response_error_msg ⇒ String (readonly)
Returns response error message.
22 23 24 |
# File 'lib/miasma/error.rb', line 22 def response_error_msg @response_error_msg end |
Instance Method Details
#extract_error_message(response) ⇒ String, NilClass
Attempt to extract error message from response
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/miasma/error.rb', line 45 def (response) begin begin content = MultiJson.load(response.body.to_s).to_smash @response_error_msg = [[:error, :message]].map do |path| if(result = content.get(*path)) "#{content[:code]}: #{result}" end end.flatten.compact.first rescue MultiJson::ParseError begin content = MultiXml.parse(response.body.to_s).to_smash @response_error_msg = [['ErrorResponse', 'Error'], ['Error']].map do |path| if(result = content.get(*path)) "#{result['Code']}: #{result['Message']}" end end.compact.first rescue MultiXml::ParseError content = Smash.new end rescue # do nothing end end @response_error_msg end |
#message ⇒ String
Returns provides response error suffix.
37 38 39 |
# File 'lib/miasma/error.rb', line 37 def [@message, @response_error_msg].compact.join(' - ') end |