Class: Weft::Defaults::ErrorComponent

Inherits:
Component
  • Object
show all
Defined in:
lib/weft/defaults/error_component.rb

Overview

Gem-default component rendered when an action or partial-render fails and no user-declared recovers entry matches. Verbose mode shows the exception class and message; non-verbose shows a generic message. Users override by setting Weft.configuration.error_component or by declaring their own recovers chain.

Doubles as the default recovery frame for SSE push failures: the Router injects :attempts_remaining only on that path, so its presence switches the build into push shape — a countdown notice while the stream retries, then a stopped notice with a reopen button on the final frame.

Constant Summary collapse

STYLE =
"padding:1rem; border:1px solid #fca5a5; border-radius:6px; " \
"background:#fef2f2; color:#991b1b; font-size:0.875rem"
HEADING_STYLE =
"font-weight:600; margin-bottom:0.5rem"
MONO_STYLE =
"margin-bottom:0.5rem; font-family:monospace; font-size:0.8rem"
BUTTON_STYLE =
"padding:0.25rem 0.75rem; border:1px solid #b91c1c; border-radius:4px; " \
"background:#fff; color:#b91c1c; font-size:0.75rem; cursor:pointer"

Constants inherited from Component

Component::SCALAR_ID_CLASSES

Instance Attribute Summary

Attributes included from Weft::DSL::Params

#params

Instance Method Summary collapse

Methods inherited from Component

inferred_routable?, inherited, #initialize, render, resolved_component_path, #weft_dom_id, weft_dom_id_for, #weft_url

Methods included from Registry::Eligibility

#abstract!, #routable!, #routable?

Methods included from Context::Interception

#insert_tag

Methods included from Context::Traversal

#closest, #closest!, #enclosing, #enclosing!

Methods included from Weft::DSL::Containers

behavior_for, included

Methods included from Weft::DSL::Actions

included

Methods included from Weft::DSL::Updates

included

Methods included from Weft::DSL::Inclusions

included

Methods included from Weft::DSL::Triggers

included

Methods included from Weft::DSL::Recoveries

included

Methods included from Weft::DSL::Params

included, #serializable_params, warned_collisions

Constructor Details

This class inherits a constructor from Weft::Component

Instance Method Details

#build(attributes = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/weft/defaults/error_component.rb', line 41

def build(attributes = {})
  super
  return build_push_error if push_context?

  add_class "weft-error"
  set_attribute "style", STYLE

  div(style: HEADING_STYLE) { text_node "Something went wrong" }
  render_verbose if verbose?
  render_retry_button if @params.retry_url
end

#tag_nameObject

Adopt the failing component's wrapper tag when the Router injected :component_tag — a div swapped into a 's position is invalid table content; a error row is not.



56
57
58
# File 'lib/weft/defaults/error_component.rb', line 56

def tag_name
  @params.component_tag || super
end