Exception: Gini::Api::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gini-api/error.rb

Overview

Base api exception class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, api_response = nil) ⇒ Error

Parse response object and set instance vars accordingly

Parameters:

  • msg (String)

    Exception message

  • api_response (OAuth2::Response) (defaults to: nil)

    Faraday/Oauth2 response object from API



33
34
35
36
37
38
39
40
41
# 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

Instance Attribute Details

#api_messageString (readonly)

Returns Message from API error object.

Returns:

  • (String)

    Message from API error object

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

#api_methodString (readonly)

Returns HTTP method (:get, :post, :put, :delete).

Returns:

  • (String)

    HTTP method (:get, :post, :put, :delete)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

#api_reqidString (readonly)

Returns Request id from API error object.

Returns:

  • (String)

    Request id from API error object

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

#api_request_idObject (readonly)

Returns the value of attribute api_request_id.



25
26
27
# File 'lib/gini-api/error.rb', line 25

def api_request_id
  @api_request_id
end

#api_responseFaraday::Response (readonly)

Returns Faraday response object.

Returns:

  • (Faraday::Response)

    Faraday response object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

#api_statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

#api_urlString (readonly)

Returns Request URL.

Returns:

  • (String)

    Request URL



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

#docidString

Returns Optional document-id that caused the exception.

Returns:

  • (String)

    Optional document-id that caused the exception



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
# File 'lib/gini-api/error.rb', line 23

class Error < StandardError
  attr_reader   :api_response, :api_method, :api_url
  attr_reader   :api_status, :api_message, :api_request_id
  attr_accessor :docid

  # Parse response object and set instance vars accordingly
  #
  # @param [String] msg Exception message
  # @param [OAuth2::Response] api_response Faraday/Oauth2 response object from API
  #
  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

  # Build api error message rom api response
  #
  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 Faraday response and fill instance variables
  #
  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
end

Instance Method Details

#api_errorObject

Build api error message rom api response



45
46
47
48
49
50
51
52
53
# 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_responseObject

Parse Faraday response and fill instance variables



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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