Exception: TurboBoost::Commands::CommandError

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

Direct Known Subclasses

AbortError, PerformError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*messages, command:, http_status:, cause: nil) ⇒ CommandError

Returns a new instance of CommandError.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/turbo_boost/commands/errors.rb', line 11

def initialize(*messages, command:, http_status:, cause: nil)
  @cause = cause
  @command = command
  @http_status_code = TurboBoost::Commands.http_status_code(http_status)

  messages.prepend "HTTP #{http_status_code} #{TurboBoost::Commands::HTTP_STATUS_CODES[http_status_code]}"
  messages << cause.message if cause
  messages << location

  super(messages.uniq.select(&:present?).join("; "))
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



23
24
25
# File 'lib/turbo_boost/commands/errors.rb', line 23

def cause
  @cause
end

#commandObject (readonly)

Returns the value of attribute command.



23
24
25
# File 'lib/turbo_boost/commands/errors.rb', line 23

def command
  @command
end

#http_status_codeObject (readonly)

Returns the value of attribute http_status_code.



23
24
25
# File 'lib/turbo_boost/commands/errors.rb', line 23

def http_status_code
  @http_status_code
end

Instance Method Details

#locationObject



25
26
27
28
# File 'lib/turbo_boost/commands/errors.rb', line 25

def location
  line = (cause&.backtrace || []).first.to_s
  line.[](/[^\/]+\.rb:\d+/i)
end