Exception: Octobat::OctobatError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/octobat/errors/octobat_error.rb

Direct Known Subclasses

InvalidRequestError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error = nil, http_status = nil, http_body = nil, json_body = nil) ⇒ OctobatError

Returns a new instance of OctobatError.



9
10
11
12
13
14
# File 'lib/octobat/errors/octobat_error.rb', line 9

def initialize(error=nil, http_status=nil, http_body=nil, json_body=nil)
  @error = error
  @http_status = http_status
  @http_body = http_body
  @json_body = json_body
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/octobat/errors/octobat_error.rb', line 4

def error
  @error
end

#http_bodyObject (readonly)

Returns the value of attribute http_body.



6
7
8
# File 'lib/octobat/errors/octobat_error.rb', line 6

def http_body
  @http_body
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



5
6
7
# File 'lib/octobat/errors/octobat_error.rb', line 5

def http_status
  @http_status
end

#json_bodyObject (readonly)

Returns the value of attribute json_body.



7
8
9
# File 'lib/octobat/errors/octobat_error.rb', line 7

def json_body
  @json_body
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/octobat/errors/octobat_error.rb', line 3

def message
  @message
end

Instance Method Details

#generate_message_from_errorObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/octobat/errors/octobat_error.rb', line 25

def generate_message_from_error
  return "" if @error.nil?
  a = []
  
  @error.each_key do |k|
    msg = k.eql?(:global) ? "" : "#{k.to_s}: "
    msg << "#{serialize_errors_from(@error[k])}"
    a << msg
  end
  
  a.join(". ")
end

#serialize_errors_from(err) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/octobat/errors/octobat_error.rb', line 38

def serialize_errors_from(err)
  a = []
  err.each do |e|
    a << "#{e[:details]}"
  end
  a.join(', ')
end

#to_sObject



20
21
22
23
# File 'lib/octobat/errors/octobat_error.rb', line 20

def to_s
  status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
  "#{status_string}#{message}"
end