Class: GraphQL::Schema::RescueMiddleware Private
- Inherits:
-
Object
- Object
- GraphQL::Schema::RescueMiddleware
- Defined in:
- lib/graphql/schema/rescue_middleware.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
- Store a table of errors & handlers
- Rescue errors in a middleware chain, then check for a handler
- If a handler is found, use it & return a ExecutionError
- If no handler is found, re-raise the error
Instance Attribute Summary collapse
-
#rescue_table ⇒ Hash
readonly
private
{class => proc}
pairs for handling errors.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
private
Implement the requirement for MiddlewareChain.
-
#initialize ⇒ RescueMiddleware
constructor
private
A new instance of RescueMiddleware.
-
#remove_handler(*error_classes) ⇒ Object
private
Remove the handler for
error_classs
. -
#rescue_from(*error_classes) {|err| ... } ⇒ Object
private
Constructor Details
#initialize ⇒ RescueMiddleware
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RescueMiddleware
11 12 13 |
# File 'lib/graphql/schema/rescue_middleware.rb', line 11 def initialize @rescue_table = {} end |
Instance Attribute Details
#rescue_table ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns {class => proc}
pairs for handling errors
10 11 12 |
# File 'lib/graphql/schema/rescue_middleware.rb', line 10 def rescue_table @rescue_table end |
Instance Method Details
#call(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Implement the requirement for MiddlewareChain
33 34 35 36 37 38 39 |
# File 'lib/graphql/schema/rescue_middleware.rb', line 33 def call(*args) begin yield rescue StandardError => err attempt_rescue(err) end end |
#remove_handler(*error_classes) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remove the handler for error_classs
28 29 30 |
# File 'lib/graphql/schema/rescue_middleware.rb', line 28 def remove_handler(*error_classes) error_classes.map{ |error_class| rescue_table.delete(error_class) } end |
#rescue_from(*error_classes) {|err| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/graphql/schema/rescue_middleware.rb', line 22 def rescue_from(*error_classes, &block) error_classes.map{ |error_class| rescue_table[error_class] = block } end |