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

Class Method Summary collapse

Class Method Details

.exception_view(card, exception) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/card/error.rb', line 47

def exception_view card, 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 Wagn::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



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/card/error.rb', line 70

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



85
86
87
88
89
90
91
92
# File 'lib/card/error.rb', line 85

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