Exception: UU::OS::Server::ImmediateResponse

Inherits:
Exception
  • Object
show all
Defined in:
uu_os_connection-server-2.3.1/lib/uu/os/server/immediate_response.rb

Overview

Note:

Not intended for regular use. Use should be avoided in common control methods!

Special type of exception to be raised anywhere in controller implementation (including overridden system request processing methods) which causes interruption of processing and immediate return of given response.

Instance Attribute Summary

Attributes inherited from Exception

#code, #id, #timestamp

Instance Method Summary (collapse)

Constructor Details

- (ImmediateResponse) initialize(status, headers, body)

Creates new instance of immediate response exception.

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'uu_os_connection-server-2.3.1/lib/uu/os/server/immediate_response.rb', line 21

def initialize(status, headers, body)
  @status = status.to_i
  @headers = headers || {}
  @headers = @headers.inject({}) do |tmp, (key, value)|
    key = key.to_s.gsub('_', '-').downcase
    if value.kind_of?(Array)
      tmp[key] = value.join(',')
    else
      tmp[key] = value.to_s
    end
    tmp
  end
  if body.kind_of?(Exception)
    @body = body.to_json
    @headers['content-type'] ||= 'application/json'
  else
    @body = body
  end
end

Instance Method Details

- (Object) response

Returns response object.

Returns:

  • (Object)

    Response object to be handled by server.



43
44
45
46
# File 'uu_os_connection-server-2.3.1/lib/uu/os/server/immediate_response.rb', line 43

def response
  @body = [@body] unless @body.respond_to?(:each)
  [@status, @headers, @body]
end