Class: Praxis::RequestStages::Response

Inherits:
RequestStage show all
Defined in:
lib/praxis/request_stages/response.rb

Instance Attribute Summary

Attributes inherited from Stage

#after_callbacks, #before_callbacks, #context, #name, #stages

Instance Method Summary collapse

Methods inherited from RequestStage

#action, #controller, #execute_controller_callbacks, #execute_with_around, #path, #request, #run, #setup!, #validation_handler

Methods inherited from Stage

#after, #application, #before, #callback_args, #execute_callbacks, #initialize, #run, #setup!, #setup_deferred_callbacks!

Constructor Details

This class inherits a constructor from Praxis::Stage

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/praxis/request_stages/response.rb', line 6

def execute
  response = controller.response

  response.handle

  if Application.instance.config.praxis.validate_responses == true
    validate_body = Application.instance.config.praxis.validate_response_bodies

    response.validate(action, validate_body: validate_body)
  end
rescue Exceptions::Validation => e
  controller.response = validation_handler.handle!(
    summary: "Error validating response", 
    exception: e,
    request: request,
    stage: name, 
    errors: e.errors
  )
  retry
end