From 4c901c31308991c5a701d57ff58e2a798ef5e643 Mon Sep 17 00:00:00 2001 From: Colin Adams Date: Thu, 8 Aug 2013 10:39:46 +0100 Subject: [PATCH] Implemented remaining error response calls --- library/server/wsf/router/wsf_delete_helper.e | 3 +- library/server/wsf/router/wsf_method_helper.e | 30 +++++++++++++++---- .../server/wsf/router/wsf_skeleton_handler.e | 1 + .../utility/general/error/src/error_handler.e | 10 +++++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/library/server/wsf/router/wsf_delete_helper.e b/library/server/wsf/router/wsf_delete_helper.e index a8633d4b..77baf03d 100644 --- a/library/server/wsf/router/wsf_delete_helper.e +++ b/library/server/wsf/router/wsf_delete_helper.e @@ -47,8 +47,7 @@ feature {NONE} -- Implementation res.put_header_text (a_header.string) end else - -- TODO - req.error_handler.has_error = True - --handle_internal_server_error (a_handler.last_error (req), req, res) + write_error_response (req, res) end end diff --git a/library/server/wsf/router/wsf_method_helper.e b/library/server/wsf/router/wsf_method_helper.e index a37e9c3b..ca527161 100644 --- a/library/server/wsf/router/wsf_method_helper.e +++ b/library/server/wsf/router/wsf_method_helper.e @@ -248,8 +248,7 @@ feature {NONE} -- Implementation l_chunk := a_handler.next_chunk (req, a_media_type, a_language_type, a_character_type, a_compression_type) res.put_chunk (l_chunk.a_chunk, l_chunk.a_extension) else - -- TODO - req.error_handler.has_error = True - -- handle_internal_server_error (a_handler.last_error (req), req, res) + write_error_response (req, res) end until a_handler.finished (req) or not a_handler.response_ok (req) @@ -259,8 +258,7 @@ feature {NONE} -- Implementation l_chunk := a_handler.next_chunk (req, a_media_type, a_language_type, a_character_type, a_compression_type) res.put_chunk (l_chunk.a_chunk, l_chunk.a_extension) else - -- TODO - req.error_handler.has_error = True - -- handle_internal_server_error (a_handler.last_error (req), req, res) + write_error_response (req, res) end end if a_handler.finished (req) then @@ -334,7 +332,29 @@ feature {NONE} -- Implementation end end -feature -- Basic operations +feature -- Errors + + +feature -- Error reporting + + write_error_response (req: WSF_REQUEST; res: WSF_RESPONSE) + -- Write an error response to `res' using `req.error_handler'. + require + req_attached: req /= Void + res_attached: res /= Void + req_has_error: req.has_error + local + h: HTTP_HEADER + m: READABLE_STRING_8 + do + m := req.error_handler.as_string_representation + create h.make + h.put_content_type_text_plain + h.put_content_length (m.count) + res.set_status_code (req.error_handler.primary_error_code) + res.put_header_lines (h) + res.put_string (m) + end handle_redirection_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_locations: LIST [URI]; a_status_code: INTEGER) -- Write `a_status_code' error to `res'. diff --git a/library/server/wsf/router/wsf_skeleton_handler.e b/library/server/wsf/router/wsf_skeleton_handler.e index a69a6296..33a71d51 100644 --- a/library/server/wsf/router/wsf_skeleton_handler.e +++ b/library/server/wsf/router/wsf_skeleton_handler.e @@ -464,6 +464,7 @@ feature {NONE} -- Implementation h.put_content_length (m.count) h.put_current_date res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error) + res.put_header_lines (h) res.put_string (m) ensure response_status_is_set: res.status_is_set diff --git a/library/utility/general/error/src/error_handler.e b/library/utility/general/error/src/error_handler.e index e6ff72fa..f112a0c5 100644 --- a/library/utility/general/error/src/error_handler.e +++ b/library/utility/general/error/src/error_handler.e @@ -25,6 +25,16 @@ feature {NONE} -- Initialization create error_added_actions end +feature -- Access + + primary_error_code: INTEGER + -- Code of first error in `errors' + require + at_least_one_error: has_error + do + Result := errors.first.code + end + feature -- Status has_error: BOOLEAN