Exception: Card::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/card/error.rb

Overview

exceptions and errors. (arguably most of these should be Card::Exception)

Direct Known Subclasses

BadQuery, Oops, PermissionDenied

Defined Under Namespace

Classes: Abort, BadQuery, NotFound, Oops, PermissionDenied, UnknownCodename

Class Method Summary collapse

Class Method Details

.exception_view(card, exception) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/card/error.rb', line 51

def exception_view card, exception
  Card::Error.current = exception

  case exception
  ## arguably the view and status should be defined in the error class;
  ## some are redundantly defined in view
  when Card::Error::Oops, Card::Error::BadQuery
    card.errors.add :exception, exception.message
    # these error messages are visible to end users and are generally not
    # treated as bugs.
    # Probably want to rename accordingly.
    :errors
  when Card::Error::PermissionDenied
    :denial
  when Card::Error::NotFound, ActiveRecord::RecordNotFound,
       ActionController::MissingFile
    :not_found
  when Decko::BadAddress
    :bad_address
  else
    problematic_exception_view card, exception
  end
end

.problematic_exception_view(card, exception) ⇒ Object

indicates a code problem and therefore require full logging



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/card/error.rb', line 76

def problematic_exception_view card, exception
  card.notable_exception_raised

  if exception.is_a? ActiveRecord::RecordInvalid
    :errors
  # could also just check non-production mode...
  elsif Rails.logger.level.zero?
    raise exception
  else
    :server_error
  end
end

.view_and_status(card) ⇒ Object

TODO:

should prioritize certain error classes

card view and HTTP status code associate with errors on card



91
92
93
94
95
96
97
98
# File 'lib/card/error.rb', line 91

def view_and_status card
  card.errors.keys.each do |key|
    if (view_and_status = Card.error_codes[key])
      return view_and_status
    end
  end
  nil
end