Class: ApiReference::ServerErrorException

Inherits:
APIException
  • Object
show all
Defined in:
lib/api_reference/exceptions/server_error_exception.rb

Overview

ServerError class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, response) ⇒ ServerErrorException

The constructor.

Parameters:

  • reason (String)

    The reason for raising an exception.

  • response (HttpResponse)

    The HttpReponse of the API call.



31
32
33
34
35
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 31

def initialize(reason, response)
  super(reason, response)
  hash = APIHelper.json_deserialize(@response.raw_body)
  unbox(hash)
end

Instance Attribute Details

#detailString

TODO: Write general description for this method

Returns:

  • (String)


22
23
24
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 22

def detail
  @detail
end

#statusInteger

TODO: Write general description for this method

Returns:

  • (Integer)


18
19
20
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 18

def status
  @status
end

#titleString

TODO: Write general description for this method

Returns:

  • (String)


26
27
28
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 26

def title
  @title
end

#typeString (readonly)

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 14

def type
  @type
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



55
56
57
58
59
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 55

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} type: #{@type.inspect}, status: #{@status.inspect}, detail:"\
  " #{@detail.inspect}, title: #{@title.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



49
50
51
52
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 49

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} type: #{@type}, status: #{@status}, detail: #{@detail}, title: #{@title}>"
end

#unbox(hash) ⇒ Object

Populates this object by extracting properties from a hash. response body.

Parameters:

  • hash (Hash)

    The deserialized response sent by the server in the



40
41
42
43
44
45
46
# File 'lib/api_reference/exceptions/server_error_exception.rb', line 40

def unbox(hash)
  return nil unless hash

  @status = hash.key?('status') ? hash['status'] : nil
  @detail = hash.key?('detail') ? hash['detail'] : SKIP
  @title = hash.key?('title') ? hash['title'] : SKIP
end