Sha256: c7fef6691883e9b80ff77939e412cd08037cbe37762f195e1594c587a17e8462

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# code:
# * George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id: dispatcher.rb 200 2004-12-27 11:24:41Z gmosx $

require 'nitro/server/render'

module N

# = Dispatcher
#
module Dispatcher 
	include N::Render
	
	def process(request, response)
		begin
			# gmosx, INVESTIGATE: this is not really needed.
			$og.get_connection if $og
			
			session = create_session(request, response)
			render(request.request_uri.path, request, response, session)
			response.body = @out 
		rescue Exception, StandardError => e
			$log.error "error while handling the request #{request.request_uri}"
			$log.error pp_exception(e)

			if $error_page_url
				# gmosx: SOS: TEST ME!
				# internal redirect to error page. 
				request.request_uri.path = $error_page_url
				retry
			else
				# no custom error page defined. Presen a simple yet 
				# useful error screen.
				response.header['Content-Type'] = 'text/html'
				body = %{
					<h1>ERROR</h1>
					<p>Click <a href="#{request.referer}">here</a> to return 
					to the previous page.</p>
				}
				if @rendering_errors
					body << %{
						<h3>Rendering errors</h3>
						<pre>#{@rendering_errors.join("\n")}</pre>
					}
				end
				body << %{
					<h3>Exception</h3>
					<pre>#{pp_exception(e)}</pre>
				}
				response.body = body
			end			
		ensure
			$og.put_connection if $og
		end
	end	

end

end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.7.0 lib/nitro/server/dispatcher.rb