Class: Committee::Middleware::ResponseValidation
- Defined in:
- lib/committee/middleware/response_validation.rb
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Committee::Middleware::Base
Instance Method Details
#call(env) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/committee/middleware/response_validation.rb', line 3 def call(env) status, headers, response = @app.call(env) request = Rack::Request.new(env) link_schema, type_schema = @router.routes_request?(request) if type_schema check_content_type!(headers) str = response.reduce("") { |str, s| str << s } Committee::ResponseValidator.new( MultiJson.decode(str), @schema, link_schema, type_schema ).call end [status, headers, response] rescue Committee::InvalidResponse render_error(500, :invalid_response, $!.) rescue MultiJson::LoadError render_error(500, :invalid_response, "Response wasn't valid JSON.") end |