Exception: Splunk::SplunkHTTPError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/splunk-sdk-ruby/splunk_http_error.rb

Overview

Exception to represent all errors returned from Splunkd.

The important information about the error is available as a set of accessors:

  • code: The HTTP error code returned.

  • reason: The reason field of the HTTP response header.

  • detail: The detailed error message Splunk sent in the response body.

You can also get the original response body from body and any HTTP headers returns from headers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SplunkHTTPError

Returns a new instance of SplunkHTTPError.



39
40
41
42
43
44
45
46
47
# File 'lib/splunk-sdk-ruby/splunk_http_error.rb', line 39

def initialize(response)
  @body = response.body
  @detail = Splunk::text_at_xpath("//msg", response.body)
  @reason = response.message
  @code = Integer(response.code)
  @headers = response.each().to_a()

  super("HTTP #{@code.to_s} #{@reason}: #{@detail || ""}")
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



37
38
39
# File 'lib/splunk-sdk-ruby/splunk_http_error.rb', line 37

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



37
38
39
# File 'lib/splunk-sdk-ruby/splunk_http_error.rb', line 37

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



37
38
39
# File 'lib/splunk-sdk-ruby/splunk_http_error.rb', line 37

def detail
  @detail
end

#headersObject (readonly)

Returns the value of attribute headers.



37
38
39
# File 'lib/splunk-sdk-ruby/splunk_http_error.rb', line 37

def headers
  @headers
end

#reasonObject (readonly)

Returns the value of attribute reason.



37
38
39
# File 'lib/splunk-sdk-ruby/splunk_http_error.rb', line 37

def reason
  @reason
end