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, BadAddress, BadContent, BadQuery, CodenameNotFound, NotFound, PermissionDenied
Class Method Summary collapse
-
.exception_view(card, exception) ⇒ Object
NOTE: arguably the view and status should be handled in each error class status is currently defined in the view.
-
.problematic_exception_view(card, exception) ⇒ Object
indicates a code problem and therefore require full logging.
- .simple_exception_view(card, exception) ⇒ Object
-
.view_and_status(card) ⇒ Object
card view and HTTP status code associate with errors on card TODO: should prioritize certain error classes.
Class Method Details
.exception_view(card, exception) ⇒ Object
NOTE: arguably the view and status should be handled in each error class status is currently defined in the view
58 59 60 61 62 |
# File 'lib/card/error.rb', line 58 def exception_view card, exception self.current = exception simple_exception_view(card, exception) || problematic_exception_view(card, exception) end |
.problematic_exception_view(card, exception) ⇒ Object
indicates a code problem and therefore require full logging
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/card/error.rb', line 81 def problematic_exception_view card, exception card&.notable_exception_raised if exception.is_a? ActiveRecord::RecordInvalid :errors elsif Rails.logger.level.zero? # raise error loudly when not in production (could be a better test!) raise exception else :server_error end end |
.simple_exception_view(card, exception) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/card/error.rb', line 64 def simple_exception_view card, exception # "simple" error messages are visible to end users and are generally not # treated as software bugs (though they may be "ruler" bugs) case exception when BadContent, BadQuery card.errors.add :exception, exception. :errors when BadAddress :bad_address when PermissionDenied :denial when NotFound, ActiveRecord::RecordNotFound, ActionController::MissingFile :not_found end end |
.view_and_status(card) ⇒ Object
card view and HTTP status code associate with errors on card TODO: should prioritize certain error classes
96 97 98 99 100 101 102 103 |
# File 'lib/card/error.rb', line 96 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 |