Class: Rad::Processors::HttpWriter

Inherits:
Rad::Processor show all
Defined in:
lib/rad/http/processors/http_writer.rb

Instance Attribute Summary

Attributes inherited from Rad::Processor

#next_processor

Instance Method Summary collapse

Methods inherited from Rad::Processor

#initialize, inspect

Constructor Details

This class inherits a constructor from Rad::Processor

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rad/http/processors/http_writer.rb', line 4

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