Exception: TurboBoost::Commands::CommandError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CommandError.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/turbo_boost/commands/errors.rb', line 8

def initialize(*messages, command:, http_status: :internal_server_error, 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.



20
21
22
# File 'lib/turbo_boost/commands/errors.rb', line 20

def cause
  @cause
end

#commandObject (readonly)

Returns the value of attribute command.



20
21
22
# File 'lib/turbo_boost/commands/errors.rb', line 20

def command
  @command
end

#http_status_codeObject (readonly)

Returns the value of attribute http_status_code.



20
21
22
# File 'lib/turbo_boost/commands/errors.rb', line 20

def http_status_code
  @http_status_code
end

Instance Method Details

#locationObject



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

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