Exception: DogTrainer::DogApiException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/dogtrainer/dogapiexception.rb

Overview

Exception raised for Datadog API errors (non-200 status code)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ DogApiException

Returns a new instance of DogApiException.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dogtrainer/dogapiexception.rb', line 7

def initialize(response)
  @statuscode = response[0]
  @content = if response.length > 1
               response[1]
             else
               {}
             end
  msg = "Datadog API call returned status #{@statuscode}"
  if @content.include?('errors')
    msg << ":\n"
    if @content['errors'].is_a?(Array)
      @content['errors'].each { |e| msg << "#{e}\n" }
    else
      msg << "#{content['errors']}\n"
    end
  end
  super(msg)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/dogtrainer/dogapiexception.rb', line 5

def content
  @content
end

#statuscodeObject (readonly)

Returns the value of attribute statuscode.



4
5
6
# File 'lib/dogtrainer/dogapiexception.rb', line 4

def statuscode
  @statuscode
end