Class: Weft::Defaults::ErrorComponent
- 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
Instance Attribute Summary
Attributes included from Weft::DSL::Params
Instance Method Summary collapse
- #build(attributes = {}) ⇒ Object
-
#tag_name ⇒ Object
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. 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
Methods included from Context::Traversal
#closest, #closest!, #enclosing, #enclosing!
Methods included from Weft::DSL::Containers
Methods included from Weft::DSL::Actions
Methods included from Weft::DSL::Updates
Methods included from Weft::DSL::Inclusions
Methods included from Weft::DSL::Triggers
Methods included from Weft::DSL::Recoveries
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? if @params.retry_url end
#tag_name ⇒ Object
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