Module: Card::Format::Error

Included in:
Card::Format
Defined in:
card/lib/card/format/error.rb

Instance Method Summary collapse

Instance Method Details

#anyone_can?(task) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'card/lib/card/format/error.rb', line 9

def anyone_can? task
  return false unless task.is_a? Symbol

  @anyone_can ||= {}
  @anyone_can[task] = card.anyone_can? task if @anyone_can[task].nil?
  @anyone_can[task]
end

#error_cardname(_exception) ⇒ Object



46
47
48
49
50
51
52
# File 'card/lib/card/format/error.rb', line 46

def error_cardname _exception
  if card&.name.present?
    safe_name
  else
    Cardio.t :lib_no_cardname
  end
end

#log_error(e) ⇒ Object



70
71
72
73
# File 'card/lib/card/format/error.rb', line 70

def log_error e
  Rails.logger.info e.message
  Rails.logger.debug e.backtrace.join("\n")
end

#loud_error(e, view) ⇒ Object



58
59
60
61
62
# File 'card/lib/card/format/error.rb', line 58

def loud_error e, view
  log_error e if focal? && voo.root?
  card.errors.add "#{view} view", rendering_error(e, view) if card.errors.empty?
  raise e
end

#loud_error?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'card/lib/card/format/error.rb', line 54

def loud_error?
  focal? || Card.config.raise_all_rendering_errors
end

#monitor_depthObject



32
33
34
35
36
37
38
39
# File 'card/lib/card/format/error.rb', line 32

def monitor_depth
  if depth >= Card.config.max_depth
    raise Card::Error::UserError,
          t(:format_too_deep)
  end

  yield
end

#ok?(task) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'card/lib/card/format/error.rb', line 4

def ok? task
  task = :create if task == :update && card.new_card?
  card.ok? task
end

#quiet_error(e, view) ⇒ Object



64
65
66
67
68
# File 'card/lib/card/format/error.rb', line 64

def quiet_error e, view
  # TODO: unify with Card::Error#report
  log_error e
  rendering_error e, view
end

#rendering_error(exception, view) ⇒ Object



75
76
77
78
79
80
81
# File 'card/lib/card/format/error.rb', line 75

def rendering_error exception, view
  if exception.is_a? Card::Error::UserError
    exception.message
  else
    t :lib_error_rendering, cardname: error_cardname(exception), view: view
  end
end

#rescue_view(e, view) ⇒ Object



41
42
43
44
# File 'card/lib/card/format/error.rb', line 41

def rescue_view e, view
  method = loud_error? ? :loud_error : :quiet_error
  send method, e, view
end

#view_for_denial(view, task) ⇒ Object



26
27
28
29
30
# File 'card/lib/card/format/error.rb', line 26

def view_for_denial view, task
  @denied_task = task
  root.error_status = 403 if focal? && voo.root?
  view_setting(:denial, view) || :denial
end

#view_for_unknown(_view) ⇒ Object



17
18
19
20
21
22
23
24
# File 'card/lib/card/format/error.rb', line 17

def view_for_unknown _view
  if main?
    root.error_status = 404
    :not_found
  else
    :unknown
  end
end