Class: Grape::Exceptions::ErrorResponse
- Inherits:
-
Data
- Object
- Data
- Grape::Exceptions::ErrorResponse
- Defined in:
- lib/grape/exceptions/error_response.rb
Overview
Value object representing the payload thrown via ‘throw :error, …` and consumed by `Middleware::Error#error_response`. Replaces the implicit-schema Hash that previously circulated between throw sites and the error middleware.
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#original_exception ⇒ Object
readonly
Returns the value of attribute original_exception.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.coerce(input) ⇒ Object
Normalize heterogeneous inputs into an ErrorResponse.
- .from_exception(exception) ⇒ Object
Instance Method Summary collapse
-
#initialize(status: nil, message: nil, headers: nil, backtrace: nil, original_exception: nil) ⇒ ErrorResponse
constructor
A new instance of ErrorResponse.
- #to_s ⇒ Object
Constructor Details
#initialize(status: nil, message: nil, headers: nil, backtrace: nil, original_exception: nil) ⇒ ErrorResponse
Returns a new instance of ErrorResponse.
10 11 12 |
# File 'lib/grape/exceptions/error_response.rb', line 10 def initialize(status: nil, message: nil, headers: nil, backtrace: nil, original_exception: nil) super end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace
9 10 11 |
# File 'lib/grape/exceptions/error_response.rb', line 9 def backtrace @backtrace end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers
9 10 11 |
# File 'lib/grape/exceptions/error_response.rb', line 9 def headers @headers end |
#message ⇒ Object (readonly)
Returns the value of attribute message
9 10 11 |
# File 'lib/grape/exceptions/error_response.rb', line 9 def @message end |
#original_exception ⇒ Object (readonly)
Returns the value of attribute original_exception
9 10 11 |
# File 'lib/grape/exceptions/error_response.rb', line 9 def original_exception @original_exception end |
#status ⇒ Object (readonly)
Returns the value of attribute status
9 10 11 |
# File 'lib/grape/exceptions/error_response.rb', line 9 def status @status end |
Class Method Details
.coerce(input) ⇒ Object
Normalize heterogeneous inputs into an ErrorResponse. Preserves the public contract that users can still ‘throw :error, hash` from their own middleware or `rescue_from` handlers.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grape/exceptions/error_response.rb', line 31 def self.coerce(input) case input when ErrorResponse input when Grape::Exceptions::Base from_exception(input) when Hash new(**input.slice(:status, :message, :headers, :backtrace, :original_exception)) else new end end |
.from_exception(exception) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/grape/exceptions/error_response.rb', line 18 def self.from_exception(exception) new( status: exception.status, message: exception., headers: exception.headers, backtrace: exception.backtrace, original_exception: exception ) end |
Instance Method Details
#to_s ⇒ Object
14 15 16 |
# File 'lib/grape/exceptions/error_response.rb', line 14 def to_s "#<#{self.class.name} status=#{status.inspect} message=#{.inspect} headers=#{headers.inspect}>" end |