Exception: HatiCommand::Errors::BaseError

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

Overview

Custom BaseError class for command issues scenarios in HatiCommand

Examples:

Raising a BaseError with a message

raise HatiCommand::Error::BaseError, "Operation failed"

Constant Summary collapse

DEFAULT_MSG =
'Default message: Oooops! Something went wrong. Please check the logs.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, failure_obj: nil) ⇒ BaseError

Returns a new instance of BaseError.

Parameters:

  • message (String) (defaults to: nil)

    The error message

  • failure_obj (Object) (defaults to: nil)

    An optional Error || Failure DTO



16
17
18
19
20
# File 'lib/hati_command/errors/base_error.rb', line 16

def initialize(message = nil, failure_obj: nil)
  msg = build_msg + (message || default_message)
  super(msg)
  @failure_obj = failure_obj
end

Instance Attribute Details

#failure_objObject (readonly)

Returns the value of attribute failure_obj.



12
13
14
# File 'lib/hati_command/errors/base_error.rb', line 12

def failure_obj
  @failure_obj
end

Instance Method Details

#build_msgObject



26
27
28
# File 'lib/hati_command/errors/base_error.rb', line 26

def build_msg
  "[#{error_klass}] "
end

#default_messageObject



30
31
32
# File 'lib/hati_command/errors/base_error.rb', line 30

def default_message
  DEFAULT_MSG
end

#error_klassObject



22
23
24
# File 'lib/hati_command/errors/base_error.rb', line 22

def error_klass
  self.class.name
end