added exception handling in Requesthandler, added WebWidgetsException

This commit is contained in:
Peter Schojer 2008-06-06 08:24:57 +00:00
parent e8111249e5
commit d2eaf40e88
8 changed files with 152 additions and 4 deletions

View File

@ -75,7 +75,7 @@ public:
static void renderButton(const ButtonCell* pCell, const std::string& content, bool writeId, bool submitButton, std::ostream& ostr, bool showText = true);
/// Renders button properties
static void addClickServerCallback(Button* pCombo, const std::string& onSuccess, const std::string& onFailure);
static void addClickServerCallback(Button* pCombo, const std::string& onSuccess="", const std::string& onFailure="");
/// Adds a server callback for the buttonClicked event. The JS method signature for click is
/// click : ( Button this, EventObject e )

View File

@ -114,6 +114,15 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
ostr << "<script type=\"text/javascript\">";
ostr << "Ext.onReady(function() {";
ostr << "Ext.QuickTips.init();";
ostr << "Ext.Ajax.on({'requestexception':function(conn, resp, obj){";
ostr << "Ext.Msg.show({";
ostr << "title:'Server Error',";
ostr << "msg:resp.statusText,";
ostr << "buttons:Ext.Msg.OK,";
ostr << "icon:Ext.MessageBox.ERROR";
ostr << "});";
ostr << "}});";
// always nest a panel around, so we can get rid of dynamic casts to check for parent type
ostr << "new Ext.Panel({renderTo:'p" << pPage->id() << "',border:false,bodyBorder:false";
if (!pPage->beforeRender.jsDelegates().empty() || !pPage->afterRender.jsDelegates().empty())

View File

@ -142,13 +142,13 @@ void Utility::initialize(ResourceManager::Ptr ptr, const Poco::Path& extJSDir)
ptr->appendJSInclude(Poco::Path(aDir, "ext-base.js"));
ptr->appendJSInclude(Poco::Path(aDir, "ext-all.js"));
ptr->appendJSInclude(Poco::Path(aDir, "DDView.js"));
ptr->appendJSInclude(Poco::Path(aDir, "MultiSelect.js"));
ptr->appendJSInclude(Poco::Path(aDir, "Multiselect.js"));
Poco::Path cssAll("resources/css/ext-all.css");
cssAll.makeFile();
ptr->appendCSSInclude(Poco::Path(aDir, cssAll));
ptr->appendCSSInclude(Poco::Path(aDir, "MultiSelect.css"));
ptr->appendCSSInclude(Poco::Path(aDir, "Multiselect.css"));
}

View File

@ -285,6 +285,10 @@
RelativePath=".\include\Poco\WebWidgets\WebWidgets.h"
>
</File>
<File
RelativePath=".\include\Poco\WebWidgets\WebWidgetsException.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
@ -349,6 +353,10 @@
RelativePath=".\src\WebApplication.cpp"
>
</File>
<File
RelativePath=".\src\WebWidgetsException.cpp"
>
</File>
</Filter>
</Filter>
<Filter

View File

@ -284,6 +284,10 @@
RelativePath=".\include\Poco\WebWidgets\WebWidgets.h"
>
</File>
<File
RelativePath=".\include\Poco\WebWidgets\WebWidgetsException.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
@ -348,6 +352,10 @@
RelativePath=".\src\WebApplication.cpp"
>
</File>
<File
RelativePath=".\src\WebWidgetsException.cpp"
>
</File>
</Filter>
</Filter>
<Filter

View File

@ -0,0 +1,57 @@
//
// Renderer.h
//
// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/Renderer.h#2 $
//
// Library: WebWidgets
// Package: Core
// Module: WebWidgetsException
//
// Definition of the WebWidgetsException class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef WebWidgets_WebWidgetsException_INCLUDED
#define WebWidgets_WebWidgetsException_INCLUDED
#include "Poco/WebWidgets/WebWidgets.h"
#include "Poco/Exception.h"
namespace Poco {
namespace WebWidgets {
POCO_DECLARE_EXCEPTION(WebWidgets_API, WebWidgetsException, Poco::RuntimeException);
} } // namespace Poco::WebWidgets
#endif // WebWidgets_Renderer_INCLUDED

View File

@ -41,6 +41,7 @@
#include "Poco/WebWidgets/Page.h"
#include "Poco/WebWidgets/RenderContext.h"
#include "Poco/WebWidgets/RequestProcessor.h"
#include "Poco/WebWidgets/WebWidgetsException.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/URI.h"
@ -130,9 +131,27 @@ void RequestHandler::handleAjaxRequest(Poco::Net::HTTPServerRequest& request, Po
{
pProc->handleAjaxRequest(args, response);
}
catch(WebWidgetsException& e)
{
Poco::Net::HTTPResponse::HTTPStatus code = Poco::Net::HTTPResponse::HTTP_BAD_REQUEST;
if (e.code() > code && e.code() <= Poco::Net::HTTPResponse::HTTP_EXPECTATION_FAILED)
code = (Poco::Net::HTTPResponse::HTTPStatus)e.code();
response.setStatusAndReason(code, e.displayText());
response.send();
}
catch(Poco::Exception& e)
{
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, e.displayText());
response.send();
}
catch(std::exception& e)
{
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, e.what());
response.send();
}
catch(...)
{
response.setStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, "Unknown exception");
response.send();
}
}

View File

@ -0,0 +1,47 @@
//
// Renderer.cpp
//
// $Id: //poco/Main/WebWidgets/src/Renderer.cpp#2 $
//
// Library: WebWidgets
// Package: Core
// Module: WebWidgetsException
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/WebWidgets/WebWidgetsException.h"
namespace Poco {
namespace WebWidgets {
POCO_IMPLEMENT_EXCEPTION(WebWidgetsException, Poco::RuntimeException, "WebWidgetsException");
} } // namespace Poco::WebWidgets