Sha256: 327b3209bad3cc02de2def84457ed16b5b7fb8d6e694c79305705ad77b8b9027

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

module Rad
  module Processors    
    class HttpWriter < Processor      
      def call
        response = workspace.response.must_be.defined
        
        begin
          next_processor.call

          response.body = workspace.content if response.body.blank? and workspace.content?
          response.content_type ||= Mime[(workspace.params.format if workspace.params?) || config.default_format]
        rescue StandardError => e       
          raise e if config.test?
          
          response.clear          
          if workspace.params.format? and workspace.params.format == 'json'
            response.body = {error: (config.production? ? "Internal error!" : e.message)}.to_json
            response.content_type = Mime.json
          else
            response.body = (config.production? ? "Internal error!" : e.message)
            response.content_type = Mime.text
          end
          
          logger.error e
          logger.info "\n"
        end
      end
    end 
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/http/processors/http_writer.rb