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.

Constant Summary collapse

STYLE =
"padding:1rem; border:1px solid #fca5a5; border-radius:6px; " \
"background:#fef2f2; color:#991b1b; font-size:0.875rem"
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"

Instance Attribute Summary

Attributes included from Weft::DSL::Attributes

#attrs

Instance Method Summary collapse

Methods inherited from Component

inferred_routable?, inherited, render, resolved_component_path, weft_id_for, #weft_url

Methods included from Registry::Eligibility

#abstract!, #routable!, #routable?, #stale?

Methods included from Context::Interception

#insert_tag

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::Attributes

included

Instance Method Details

#build(attributes = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/weft/defaults/error_component.rb', line 32

def build(attributes = {})
  super
  add_class "weft-error"
  set_attribute "style", STYLE

  div(style: "font-weight:600; margin-bottom:0.5rem") { text_node "Something went wrong" }
  render_verbose if Weft.configuration.verbose_error_pages && @attrs.exception
  render_retry_button if @attrs.retry_url
end

#weft_idObject

Preserve the failing component's DOM identity when the Router injected :component_id. Otherwise fall back to the class-derived default.



44
45
46
# File 'lib/weft/defaults/error_component.rb', line 44

def weft_id
  @attrs.component_id || super
end