Class: Chassis::Rack::JsonBodyParser
- Inherits:
-
Rack::PostBodyContentTypeParser
- Object
- Rack::PostBodyContentTypeParser
- Chassis::Rack::JsonBodyParser
- Defined in:
- lib/chassis/rack/json_body_parser.rb
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/chassis/rack/json_body_parser.rb', line 4 def call(env) body = env[POST_BODY].read if body.strip.empty? @app.call env else begin env[POST_BODY].rewind super rescue JSON::ParserError => ex [400, { 'Content-Type' => 'text/plain' }, [ex.to_s]] end end end |