Updated the default rescue response (i.e when exception or bad internal error occurs).
Factorized the implementation in WGI_RESCUE_EXECUTION, and now by redefining the `WGI_EXECUTION.execute_rescue (...)` procedure, it is possible to have a custom response on such rescued execution.
This commit is contained in:
@@ -38,11 +38,11 @@ feature -- Execution
|
|||||||
exec.execute
|
exec.execute
|
||||||
res.push
|
res.push
|
||||||
exec.clean
|
exec.clean
|
||||||
|
elseif exec /= Void then
|
||||||
|
exec.execute_rescue ((create {EXCEPTION_MANAGER}).last_exception)
|
||||||
|
exec.clean
|
||||||
else
|
else
|
||||||
process_rescue (res)
|
(create {WGI_RESCUE_EXECUTION}).execute (req, res, (create {EXCEPTION_MANAGER}).last_exception)
|
||||||
if exec /= Void then
|
|
||||||
exec.clean
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
if not rescued then
|
if not rescued then
|
||||||
@@ -51,24 +51,6 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
process_rescue (res: detachable WGI_RESPONSE)
|
|
||||||
-- Handle rescued execution of current request.
|
|
||||||
do
|
|
||||||
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.trace as l_trace then
|
|
||||||
if res /= Void then
|
|
||||||
if not res.status_is_set then
|
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error, Void)
|
|
||||||
end
|
|
||||||
if res.message_writable then
|
|
||||||
res.put_string ("<pre>")
|
|
||||||
res.put_string (html_encoder.encoded_string (l_trace))
|
|
||||||
res.put_string ("</pre>")
|
|
||||||
end
|
|
||||||
res.push
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Eiffel Software and others"
|
copyright: "2011-2015, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ feature -- Execution
|
|||||||
exec.execute
|
exec.execute
|
||||||
res.push
|
res.push
|
||||||
exec.clean
|
exec.clean
|
||||||
|
elseif exec /= Void then
|
||||||
|
exec.execute_rescue ((create {EXCEPTION_MANAGER}).last_exception)
|
||||||
|
exec.clean
|
||||||
else
|
else
|
||||||
process_rescue (res)
|
(create {WGI_RESCUE_EXECUTION}).execute (req, res, (create {EXCEPTION_MANAGER}).last_exception)
|
||||||
if exec /= Void then
|
|
||||||
exec.clean
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
if not rescued then
|
if not rescued then
|
||||||
@@ -86,24 +86,6 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
process_rescue (res: detachable WGI_RESPONSE)
|
|
||||||
-- Handle rescued execution of current request.
|
|
||||||
do
|
|
||||||
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.trace as l_trace then
|
|
||||||
if res /= Void then
|
|
||||||
if not res.status_is_set then
|
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error, Void)
|
|
||||||
end
|
|
||||||
if res.message_writable then
|
|
||||||
res.put_string ("<pre>")
|
|
||||||
res.put_string (html_encoder.encoded_string (l_trace))
|
|
||||||
res.put_string ("</pre>")
|
|
||||||
end
|
|
||||||
res.push
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Input/Output
|
feature -- Input/Output
|
||||||
|
|
||||||
input: WGI_LIBFCGI_INPUT_STREAM
|
input: WGI_LIBFCGI_INPUT_STREAM
|
||||||
|
|||||||
@@ -88,13 +88,15 @@ feature -- Request processing
|
|||||||
exec.execute
|
exec.execute
|
||||||
res.push
|
res.push
|
||||||
exec.clean
|
exec.clean
|
||||||
else
|
elseif exec /= Void then
|
||||||
if not has_error then
|
if not has_error then
|
||||||
process_rescue (res)
|
exec.execute_rescue ((create {EXCEPTION_MANAGER}).last_exception)
|
||||||
end
|
|
||||||
if exec /= Void then
|
|
||||||
exec.clean
|
|
||||||
end
|
end
|
||||||
|
exec.clean
|
||||||
|
elseif not has_error then
|
||||||
|
(create {WGI_RESCUE_EXECUTION}).execute (req, res, (create {EXCEPTION_MANAGER}).last_exception)
|
||||||
|
else
|
||||||
|
-- Bad error.
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
if l_output = Void or else not l_output.is_available then
|
if l_output = Void or else not l_output.is_available then
|
||||||
@@ -106,31 +108,6 @@ feature -- Request processing
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
process_rescue (res: detachable WGI_RESPONSE)
|
|
||||||
local
|
|
||||||
s: STRING
|
|
||||||
do
|
|
||||||
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.trace as l_trace then
|
|
||||||
if res /= Void then
|
|
||||||
if not res.status_is_set then
|
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error, Void)
|
|
||||||
end
|
|
||||||
create s.make_empty
|
|
||||||
s.append ("<pre>")
|
|
||||||
s.append (html_encoder.encoded_string (l_trace))
|
|
||||||
s.append ("</pre>")
|
|
||||||
if not res.header_committed then
|
|
||||||
res.put_header_text ("Content-Type: text/html%R%NContent-Length: " + s.count.out + "%R%N%R%N")
|
|
||||||
end
|
|
||||||
if res.message_writable then
|
|
||||||
res.put_string (s)
|
|
||||||
end
|
|
||||||
res.push
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
httpd_environment (a_socket: HTTPD_STREAM_SOCKET): STRING_TABLE [READABLE_STRING_8]
|
httpd_environment (a_socket: HTTPD_STREAM_SOCKET): STRING_TABLE [READABLE_STRING_8]
|
||||||
local
|
local
|
||||||
p: INTEGER
|
p: INTEGER
|
||||||
|
|||||||
@@ -42,6 +42,14 @@ feature -- Execution
|
|||||||
is_valid_end_of_execution: is_valid_end_of_execution
|
is_valid_end_of_execution: is_valid_end_of_execution
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {WGI_EXPORTER, WGI_CONNECTOR} -- Execution: rescue
|
||||||
|
|
||||||
|
execute_rescue (e: detachable EXCEPTION)
|
||||||
|
-- Execute on rescue.
|
||||||
|
do
|
||||||
|
(create {WGI_RESCUE_EXECUTION}).execute (request, response, e)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
is_valid_end_of_execution: BOOLEAN
|
is_valid_end_of_execution: BOOLEAN
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
note
|
||||||
|
description: "Execution when an exception occurred."
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
WGI_RESCUE_EXECUTION
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WGI_EXPORTER
|
||||||
|
|
||||||
|
SHARED_HTML_ENCODER
|
||||||
|
|
||||||
|
feature -- Execution
|
||||||
|
|
||||||
|
execute (req: detachable WGI_REQUEST; res: detachable WGI_RESPONSE; e: detachable EXCEPTION)
|
||||||
|
-- Exception or internal error occurred, return the eventual trace
|
||||||
|
-- as response.
|
||||||
|
-- `req` and `res` may be available for processing.
|
||||||
|
local
|
||||||
|
s: STRING
|
||||||
|
do
|
||||||
|
if
|
||||||
|
res /= Void and then
|
||||||
|
e /= Void and then
|
||||||
|
attached e.trace as l_trace
|
||||||
|
then
|
||||||
|
if not res.status_is_set then
|
||||||
|
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error, Void)
|
||||||
|
end
|
||||||
|
create s.make_empty
|
||||||
|
s.append ("<pre>")
|
||||||
|
s.append (html_encoder.encoded_string (l_trace))
|
||||||
|
s.append ("</pre>")
|
||||||
|
if not res.header_committed then
|
||||||
|
-- Overwrite any header previously set.
|
||||||
|
res.put_header_text ("Content-Type: text/html%R%NContent-Length: " + s.count.out + "%R%N%R%N")
|
||||||
|
end
|
||||||
|
if res.message_writable then
|
||||||
|
res.put_string (s)
|
||||||
|
end
|
||||||
|
res.push
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user