class Gini::Api::Error
Base api exception class
@!attribute [r] api_response
@return [Faraday::Response] Faraday response object
@!attribute [r] api_method
@return [String] HTTP method (:get, :post, :put, :delete)
@!attribute [r] api_url
@return [String] Request URL
@!attribute [r] api_status
@return [Integer] HTTP status code
@!attribute [r] api_message
@return [String] Message from API error object @see http://developer.gini.net/gini-api/html/overview.html#client-errors
@!attribute [r] api_reqid
@return [String] Request id from API error object @see http://developer.gini.net/gini-api/html/overview.html#client-errors
@!attribute [r] docid
@return [String] Optional document-id that caused the exception
Attributes
api_message[R]
api_method[R]
api_request_id[R]
api_response[R]
api_status[R]
api_url[R]
docid[RW]
Public Class Methods
new(msg, api_response = nil)
click to toggle source
Parse response object and set instance vars accordingly
@param [String] msg Exception message @param [OAuth2::Response] api_response
Faraday/Oauth2 response object from API
Calls superclass method
# File lib/gini-api/error.rb, line 33 def initialize(msg, api_response = nil) super(msg) # Automatically use included response object if possible @api_response = api_response.respond_to?(:response) ? api_response.response : api_response # Parse response and set instance vars parse_response unless @api_response.nil? end
Public Instance Methods
api_error()
click to toggle source
Build api error message rom api response
# File lib/gini-api/error.rb, line 45 def api_error return nil if @api_response.nil? m = "#{@api_method.to_s.upcase} " m << "#{@api_url} : " m << "#{@api_status} - " m << "#{@api_message} (request Id: #{@api_request_id})" m end
parse_response()
click to toggle source
Parse Faraday response and fill instance variables
# File lib/gini-api/error.rb, line 57 def parse_response @api_method = @api_response.env[:method] @api_url = @api_response.env[:url].to_s @api_status = @api_response.status @api_message = 'undef' @api_request_id = 'undef' unless @api_response.body.empty? begin parsed = JSON.parse(@api_response.body, symbolize_names: true) @api_message = parsed[:message] @api_request_id = parsed[:requestId] rescue JSON::ParserError # We fail silently as defaults have been set end end end