Class: Rack::DDEX
- Inherits:
-
Object
- Object
- Rack::DDEX
- Defined in:
- lib/rack/ddex.rb
Constant Summary collapse
- HEADERS =
{"Content-Type" => "application/json"}.freeze
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rack/ddex.rb', line 9 def call(env) begin obj = ::DDEX.read(env["rack.input"]) json = JSON.dump(obj.to_hash) [200, HEADERS.merge("Content-Length" => json.bytesize.to_s), [json]] rescue => e code = e.is_a?(::DDEX::DDEXError) ? 400 : 500 json = JSON.dump(:error => e.) [code, HEADERS, [json]] end end |