Sha256: 5838b744e7b081fef132ba851e1ff28c95c9347060101b99a88bb46365c2a80b

Contents?: true

Size: 614 Bytes

Versions: 1

Compression:

Stored size: 614 Bytes

Contents

class Grape::Batch::Response
  def self.format(status, headers, response, env)
    if response
      body = response.respond_to?(:body) ? response.body.join : response.join
      parsing_failed = true

      begin
        result = MultiJson.decode(body)
        parsing_failed = false
      rescue MultiJson::ParseError
        # Captain planet to the rescue
      end
    end

    if parsing_failed || result.empty?
      status = 404
      result = { 'error' => "#{env['PATH_INFO']} not found" }
    end

    (200..299).include?(status) ? { success: result } : { code: status, error: result['error'] }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-batch-2.0.1 lib/grape/batch/response.rb