Exception: LunaPark::Errors::Http

Inherits:
System
  • Object
show all
Defined in:
lib/luna_park/errors/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, message, #message, notify, #notify?, #notify_lvl

Methods included from LunaPark::Extensions::Exceptions::Substitutive

extended

Constructor Details

#initialize(msg = nil, response:, notify: nil, **details) ⇒ Http

Create new error

Examples:

without parameters

error = Fatalism.new
error.message     # => 'You cannot change your destiny'
error.notify_lvl  # => :error
error.notify?     # => true

with custom parameters

@error = Fatalism.new 'Forgive me Kuzma, my feet are frozen', notify: false
error.message     # => 'Forgive Kuzma, my feet froze'
error.notify_lvl  # => :error
error.notify?     # => false

Parameters:

  • msg (defaults to: nil)
    • Message text

  • notify (defaults to: nil)
    • custom notify behaviour for the current instance of error (see #self.notify)

  • details
    • additional information to notifier

Raises:

  • (ArgumentError)


31
32
33
34
35
36
# File 'lib/luna_park/errors/http.rb', line 31

def initialize(msg = nil, response:, notify: nil, **details)
  raise ArgumentError, 'Response should be Http::Response' unless response.is_a? LunaPark::Http::Response

  @response = response
  super msg, notify: notify, **details
end

Instance Attribute Details

#responseObject (readonly)

Errors::Http must contain response

Returns:

  • LunaPark::Http::Response



12
13
14
# File 'lib/luna_park/errors/http.rb', line 12

def response
  @response
end

Instance Method Details

#detailsObject

Formatted details Resource does not found Http::Error.new(request: request, something: ‘important’).details # =>

#  title: 'Ping-pong',
#  status: 'OK',
#  request: {
#    body: '{"message":"ping"',
#    method: :post,
#    headers: 'application/json',
#    open_timeout: 10,
#    read_timeout: 10,
#    sent_at: nil,
#    url: 'http://example.com/api/ping'
#  },
#  response: {
#    body: '"message":"pong"',
#    code: 200,
#    headers: 'application/json',
#    cookies: 'dkmvc9saudj3cndsaosp'
#  },
#  error_details: { something: 'important' }
# }

Examples:

Error details



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/luna_park/errors/http.rb', line 66

def details # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  {
    title: request.title,
    status: response.status,
    request: {
      method: request.method,
      url: request.url,
      open_timeout: request.open_timeout,
      read_timeout: request.read_timeout,
      sent_at: request.sent_at,
      headers: request.headers,
      body: request.body
    },
    response: {
      code: response.code,
      headers: response.headers,
      cookies: response.cookies,
      body: response.body
    },
    error_details: super
  }
end

#requestObject

Return request which call this is error.



39
40
41
# File 'lib/luna_park/errors/http.rb', line 39

def request
  response.request
end