Exception: ReactOnRails::SmartError

Inherits:
Error
  • Object
show all
Defined in:
lib/react_on_rails/smart_error.rb

Overview

SmartError provides enhanced error messages with actionable suggestions rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_type:, component_name: nil, props: nil, js_code: nil, **additional_context) ⇒ SmartError

Returns a new instance of SmartError.



11
12
13
14
15
16
17
18
19
20
# File 'lib/react_on_rails/smart_error.rb', line 11

def initialize(error_type:, component_name: nil, props: nil, js_code: nil, **additional_context)
  @error_type = error_type
  @component_name = component_name
  @props = props
  @js_code = js_code
  @additional_context = additional_context

  message = build_error_message
  super(message)
end

Instance Attribute Details

#additional_contextObject (readonly)

Returns the value of attribute additional_context.



9
10
11
# File 'lib/react_on_rails/smart_error.rb', line 9

def additional_context
  @additional_context
end

#component_nameObject (readonly)

Returns the value of attribute component_name.



9
10
11
# File 'lib/react_on_rails/smart_error.rb', line 9

def component_name
  @component_name
end

#error_typeObject (readonly)

Returns the value of attribute error_type.



9
10
11
# File 'lib/react_on_rails/smart_error.rb', line 9

def error_type
  @error_type
end

#js_codeObject (readonly)

Returns the value of attribute js_code.



9
10
11
# File 'lib/react_on_rails/smart_error.rb', line 9

def js_code
  @js_code
end

#propsObject (readonly)

Returns the value of attribute props.



9
10
11
# File 'lib/react_on_rails/smart_error.rb', line 9

def props
  @props
end

Instance Method Details

#solutionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/react_on_rails/smart_error.rb', line 22

def solution
  case error_type
  when :component_not_registered
    component_not_registered_solution
  when :missing_auto_loaded_bundle
    missing_auto_loaded_bundle_solution
  when :missing_auto_loaded_store_bundle
    missing_auto_loaded_store_bundle_solution
  when :hydration_mismatch
    hydration_mismatch_solution
  when :server_rendering_error
    server_rendering_error_solution
  when :redux_store_not_found
    redux_store_not_found_solution
  when :configuration_error
    configuration_error_solution
  else
    default_solution
  end
end