Class: GraphQL::Schema::RescueMiddleware
- Inherits:
- 
      Object
      
        - Object
- GraphQL::Schema::RescueMiddleware
 
- Defined in:
- lib/graphql/schema/rescue_middleware.rb
Overview
- 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
    
    
  
  
  
  
  
  
    {class => proc}pairs for handling errors.
Instance Method Summary collapse
- 
  
    
      #call(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Implement the requirement for MiddlewareChain. 
- 
  
    
      #initialize  ⇒ RescueMiddleware 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of RescueMiddleware. 
- 
  
    
      #remove_handler(*error_classes)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Remove the handler for error_classs.
- 
  
    
      #rescue_from(*error_classes) {|err| ... } ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Constructor Details
#initialize ⇒ RescueMiddleware
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)
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
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
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
| 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 |