Exception: ResourceSpace::Error

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

Overview

Base error class for all ResourceSpace errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, data: nil, status_code: nil, response_body: nil) ⇒ Error

Initialize a new error

Parameters:

  • message (String) (defaults to: nil)

    error message

  • data (Hash) (defaults to: nil)

    additional error data

  • status_code (Integer) (defaults to: nil)

    HTTP status code

  • response_body (String) (defaults to: nil)

    HTTP response body



21
22
23
24
25
26
# File 'lib/resourcespace/errors.rb', line 21

def initialize(message = nil, data: nil, status_code: nil, response_body: nil)
  @data = data
  @status_code = status_code
  @response_body = response_body
  super(message)
end

Instance Attribute Details

#dataHash? (readonly)

Returns additional error data.

Returns:

  • (Hash, nil)

    additional error data



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

def data
  @data
end

#response_bodyString? (readonly)

Returns response body if applicable.

Returns:

  • (String, nil)

    response body if applicable



13
14
15
# File 'lib/resourcespace/errors.rb', line 13

def response_body
  @response_body
end

#status_codeInteger? (readonly)

Returns HTTP status code if applicable.

Returns:

  • (Integer, nil)

    HTTP status code if applicable



10
11
12
# File 'lib/resourcespace/errors.rb', line 10

def status_code
  @status_code
end

Instance Method Details

#to_hHash

Convert error to a hash representation

Returns:

  • (Hash)

    error as a hash



31
32
33
34
35
36
37
38
# File 'lib/resourcespace/errors.rb', line 31

def to_h
  {
    error: self.class.name,
    message: message,
    status_code: status_code,
    data: data
  }.compact
end