Class: Unit::UnitErrorPayload

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/errors/unit_error_payload.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, status, detail, details = nil, source = nil, code = nil) ⇒ UnitErrorPayload

Check out documentation link for more details: docs.unit.co/about-jsonapi/#intro-errors

Parameters:

  • title (String)

    The title of the error

  • status (String)

    The HTTP status code

  • detail (String)

    The additional information about the error

  • details (String) (defaults to: nil)

    The details of the error

  • source (Hash) (defaults to: nil)

    The source of the error

  • code (String) (defaults to: nil)

    A Unit-specific code, uniquely identifying the error type



14
15
16
17
18
19
20
21
# File 'lib/unit/errors/unit_error_payload.rb', line 14

def initialize(title, status, detail, details = nil, source = nil, code = nil)
  @title = title
  @status = status
  @detail = detail
  @details = details
  @source = source
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/unit/errors/unit_error_payload.rb', line 5

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



5
6
7
# File 'lib/unit/errors/unit_error_payload.rb', line 5

def detail
  @detail
end

#detailsObject (readonly)

Returns the value of attribute details.



5
6
7
# File 'lib/unit/errors/unit_error_payload.rb', line 5

def details
  @details
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/unit/errors/unit_error_payload.rb', line 5

def source
  @source
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/unit/errors/unit_error_payload.rb', line 5

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/unit/errors/unit_error_payload.rb', line 5

def title
  @title
end

Class Method Details

.from_json_api(error) ⇒ UnitErrorPayload

Creates a new UnitErrorPayload from given response error.

Parameters:

  • error (Hash)

    One of the errors returned in a response from Unit’s API

Returns:

  • (UnitErrorPayload)

    a new UnitErrorPayload populated with values taken from the response error



26
27
28
29
30
31
32
33
34
35
# File 'lib/unit/errors/unit_error_payload.rb', line 26

def self.from_json_api(error)
  new(
    error["title"],
    error["status"],
    error["detail"],
    error["details"],
    error["source"],
    error["code"]
  )
end