Exception: ViewModel::AbstractError
- Inherits:
-
StandardError
- Object
- StandardError
- ViewModel::AbstractError
- Defined in:
- lib/view_model/error.rb
Overview
Abstract base for renderable errors in ViewModel-based APIs. Errors of this type will be caught by ViewModel controllers and rendered in a standard format by ViewModel::ErrorView, which loosely follows errors in JSON-API.
Direct Known Subclasses
AbstractErrorCollection, AbstractErrorWithBlame, Error, Migration::NoPathError, Migration::OneWayError, Migration::UnspecifiedVersionError, SerializationError, WrappedExceptionError
Instance Method Summary collapse
-
#aggregation? ⇒ Boolean
Some types of error may be aggregations over multiple causes.
-
#causes ⇒ Object
If so, the causes of this error (as AbstractErrors).
-
#code ⇒ Object
Unique symbol identifying this error type.
-
#detail ⇒ Object
Human-readable reason for use displaying this error.
-
#exception ⇒ Object
The exception responsible for this error.
-
#initialize ⇒ AbstractError
constructor
A new instance of AbstractError.
-
#meta ⇒ Object
Additional information specific to this error type.
-
#status ⇒ Object
HTTP status code most appropriate for this error.
-
#title ⇒ Object
Human-readable title for displaying this error.
- #to_s ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize ⇒ AbstractError
Returns a new instance of AbstractError.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/view_model/error.rb', line 16 def initialize # `detail` is used to provide the exception message. However, it's not safe # to just override StandardError's `message` or `to_s` to call `detail`, # since some of Ruby's C implementation of Exceptions internally ignores # these methods and fetches the invisible internal `idMesg` attribute # instead. (!) # # This means that all fields necessary to derive the detail message must be # initialized before calling super(). super(detail) end |
Instance Method Details
#aggregation? ⇒ Boolean
Some types of error may be aggregations over multiple causes
54 55 56 |
# File 'lib/view_model/error.rb', line 54 def aggregation? false end |
#causes ⇒ Object
If so, the causes of this error (as AbstractErrors)
59 60 61 |
# File 'lib/view_model/error.rb', line 59 def causes nil end |
#code ⇒ Object
Unique symbol identifying this error type
44 45 46 |
# File 'lib/view_model/error.rb', line 44 def code 'ViewModel.AbstractError' end |
#detail ⇒ Object
Human-readable reason for use displaying this error.
29 30 31 |
# File 'lib/view_model/error.rb', line 29 def detail 'ViewModel::AbstractError' end |
#exception ⇒ Object
The exception responsible for this error. In most cases, that should be this object, but sometimes an Error may be used to wrap an external exception.
65 66 67 |
# File 'lib/view_model/error.rb', line 65 def exception self end |
#meta ⇒ Object
Additional information specific to this error type.
49 50 51 |
# File 'lib/view_model/error.rb', line 49 def {} end |
#status ⇒ Object
HTTP status code most appropriate for this error
34 35 36 |
# File 'lib/view_model/error.rb', line 34 def status 500 end |
#title ⇒ Object
Human-readable title for displaying this error
39 40 41 |
# File 'lib/view_model/error.rb', line 39 def title nil end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/view_model/error.rb', line 73 def to_s detail end |