Exception: Card::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Card::Error
- Defined in:
- lib/card/error.rb
Overview
exceptions and errors. (arguably most of these should be Card::Exception)
Direct Known Subclasses
Defined Under Namespace
Classes: Abort, BadQuery, NotFound, Oops, PermissionDenied
Class Method Summary collapse
- .exception_view(card, exception) ⇒ Object
-
.problematic_exception_view(card, exception) ⇒ Object
indicates a code problem and therefore require full logging.
-
.view_and_status(card) ⇒ Object
card view and HTTP status code associate with errors on card.
Class Method Details
.exception_view(card, exception) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/card/error.rb', line 48 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. # 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
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/card/error.rb', line 73 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
88 89 90 91 92 93 94 95 |
# File 'lib/card/error.rb', line 88 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 |