Exception: SimpleFormsApi::FormRemediation::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/simple_forms_api/form_remediation/error.rb

Constant Summary collapse

DEFAULT_MESSAGE =
'An error occurred during the form remediation process'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message: DEFAULT_MESSAGE, error: nil, details: nil, backtrace: nil) ⇒ Error

Returns a new instance of Error.



10
11
12
13
14
15
# File 'lib/simple_forms_api/form_remediation/error.rb', line 10

def initialize(message: DEFAULT_MESSAGE, error: nil, details: nil, backtrace: nil)
  super(message)
  @base_error = error
  @details = details
  @custom_backtrace = backtrace
end

Instance Attribute Details

#base_errorObject (readonly)

Returns the value of attribute base_error.



6
7
8
# File 'lib/simple_forms_api/form_remediation/error.rb', line 6

def base_error
  @base_error
end

#detailsObject (readonly)

Returns the value of attribute details.



6
7
8
# File 'lib/simple_forms_api/form_remediation/error.rb', line 6

def details
  @details
end

Instance Method Details

#backtraceObject



21
22
23
# File 'lib/simple_forms_api/form_remediation/error.rb', line 21

def backtrace
  @custom_backtrace || base_error&.backtrace || super
end

#custom_messageObject (private)



27
28
29
# File 'lib/simple_forms_api/form_remediation/error.rb', line 27

def custom_message
  details.is_a?(Hash) ? details[:message] : base_error&.message
end

#messageObject



17
18
19
# File 'lib/simple_forms_api/form_remediation/error.rb', line 17

def message
  [super, custom_message].compact.join(' - ')
end