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)
-
- (HTTP::Response) response
readonly
Result of bad request.
-
- (String) response_error_msg
readonly
Response error message.
Instance Method Summary (collapse)
-
- (String, NilClass) extract_error_message(response)
Attempt to extract error message from response.
-
- (ApiError) initialize(msg, args = {})
constructor
Create new API error instance.
-
- (String) message
Provides response error suffix.
Constructor Details
- (ApiError) initialize(msg, args = {})
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
- (HTTP::Response) response (readonly)
Returns result of bad request
20 21 22 |
# File 'lib/miasma/error.rb', line 20 def response @response end |
- (String) response_error_msg (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
- (String, NilClass) extract_error_message(response)
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 |
- (String) message
Returns provides response error suffix
37 38 39 |
# File 'lib/miasma/error.rb', line 37 def [@message, @response_error_msg].compact.join(' - ') end |