From bf76d0f770958b5ca30ed85b84ae06668c7eef79 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 16 Jan 2007 12:53:55 +0000 Subject: [PATCH] fixed #2112 --- .../LiveSupport/Core/XmlRpcException.h | 11 ++++ .../Core/XmlRpcMethodFaultException.h | 64 +++++++++++++++++-- .../storageClient/src/WebStorageClient.cxx | 11 ++-- .../gLiveSupport/src/UploadFileWindow.cxx | 33 ++++++++++ .../gLiveSupport/src/UploadFileWindow.h | 11 ++++ .../src/products/gLiveSupport/var/root.txt | 2 + 6 files changed, 121 insertions(+), 11 deletions(-) diff --git a/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcException.h b/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcException.h index e29295235..4470ccecf 100644 --- a/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcException.h +++ b/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcException.h @@ -114,6 +114,17 @@ class XmlRpcException : public std::exception { } + /** + * Set the message of the exception. + * + * @param msg the new message of the exception. + */ + void + setMessage(const std::string & msg) throw () + { + message.reset(new std::string(msg)); + } + /** * Get the message of the exception. * diff --git a/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcMethodFaultException.h b/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcMethodFaultException.h index 3b23d9a26..18e36e9e5 100644 --- a/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcMethodFaultException.h +++ b/campcaster/src/modules/core/include/LiveSupport/Core/XmlRpcMethodFaultException.h @@ -40,6 +40,8 @@ #include "configure.h" #endif +#include + #include "LiveSupport/Core/XmlRpcException.h" namespace LiveSupport { @@ -48,6 +50,14 @@ namespace Core { /* ================================================================ constants */ +namespace { + +/*------------------------------------------------------------------------------ + * The default fault code, the value when no fault code is set. + *----------------------------------------------------------------------------*/ +const int defaultFaultCode = -1; + +} /* =================================================================== macros */ @@ -63,6 +73,13 @@ namespace Core { */ class XmlRpcMethodFaultException : public XmlRpcException { + private: + /** + * The XML-RPC faultCode of the exception. + */ + int faultCode; + + public: /** * Constructor based on a string. @@ -70,7 +87,8 @@ class XmlRpcMethodFaultException : public XmlRpcException * @param msg the message of the exception. */ XmlRpcMethodFaultException(const std::string &msg) throw () - : XmlRpcException(msg) + : XmlRpcException(msg), + faultCode(defaultFaultCode) { } @@ -81,12 +99,13 @@ class XmlRpcMethodFaultException : public XmlRpcException */ XmlRpcMethodFaultException(const std::exception & parent) throw () - : XmlRpcException(parent) + : XmlRpcException(parent), + faultCode(defaultFaultCode) { } /** - * Constructor based on a message ant a parent exception. + * Constructor based on a message and a parent exception. * * @param msg the message of the exception. * @param parent the parent exception. @@ -94,17 +113,52 @@ class XmlRpcMethodFaultException : public XmlRpcException XmlRpcMethodFaultException(const std::string & msg, const std::exception & parent) throw () - : XmlRpcException(msg, parent) + : XmlRpcException(msg, parent), + faultCode(defaultFaultCode) { } + /** + * Constructor based on a fault code, fault string pair. + * + * @param methodName the name of the method throwing the exception. + * @param faultCode the code of the exception. + * @param faultString the message of the exception. + */ + XmlRpcMethodFaultException(const std::string & methodName, + int faultCode, + const std::string & faultString) + throw () + : XmlRpcException(""), + faultCode(faultCode) + { + std::stringstream msg; + msg << "XML-RPC method '" + << methodName + << "' returned error message:\n" + << faultCode + << " - " + << faultString; + setMessage(msg.str()); + } + /** * Virtual destructor. */ - ~XmlRpcMethodFaultException(void) throw () + ~XmlRpcMethodFaultException(void) throw () { } + /** + * Get the XML-RPC faultCode of the exception. + * + * @return the fault code, if one is set; or -1 if not. + */ + int + getFaultCode(void) const throw () + { + return faultCode; + } }; diff --git a/campcaster/src/modules/storageClient/src/WebStorageClient.cxx b/campcaster/src/modules/storageClient/src/WebStorageClient.cxx index 63a1b03af..005fddeac 100644 --- a/campcaster/src/modules/storageClient/src/WebStorageClient.cxx +++ b/campcaster/src/modules/storageClient/src/WebStorageClient.cxx @@ -1102,12 +1102,11 @@ WebStorageClient :: execute(const std::string & methodName, xmlRpcClient.close(); if (xmlRpcClient.isFault()) { - std::stringstream eMsg; - eMsg << "XML-RPC method '" - << methodName - << "' returned error message:\n" - << result; - throw Core::XmlRpcMethodFaultException(eMsg.str()); + int faultCode = result[errorCodeParamName]; + std::string faultString = result[errorMessageParamName]; + throw Core::XmlRpcMethodFaultException(methodName, + faultCode, + faultString); } } diff --git a/campcaster/src/products/gLiveSupport/src/UploadFileWindow.cxx b/campcaster/src/products/gLiveSupport/src/UploadFileWindow.cxx index 8c391d023..cae1d3fb5 100644 --- a/campcaster/src/products/gLiveSupport/src/UploadFileWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/UploadFileWindow.cxx @@ -43,6 +43,7 @@ #include #include +#include "LiveSupport/Core/Debug.h" #include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Core/FileTools.h" @@ -469,6 +470,11 @@ UploadFileWindow :: uploadAudioClip(void) throw () try { gLiveSupport->uploadAudioClip(audioClip); + + } catch (XmlRpcMethodFaultException &e) { + statusBar->set_text(*processException(e)); + return; + } catch (XmlRpcException &e) { statusBar->set_text(e.what()); std::cerr << e.what(); @@ -494,6 +500,11 @@ UploadFileWindow :: uploadPlaylistArchive(void) throw () Ptr::Ref playlist; try { playlist = gLiveSupport->uploadPlaylistArchive(path); + + } catch (XmlRpcMethodFaultException &e) { + statusBar->set_text(*processException(e)); + return; + } catch (XmlRpcException &e) { statusBar->set_text(e.what()); return; @@ -619,3 +630,25 @@ UploadFileWindow :: clearEverything(void) throw () fileType = invalidType; } + +/*------------------------------------------------------------------------------ + * Handle some known exception types. + *----------------------------------------------------------------------------*/ +Ptr::Ref +UploadFileWindow :: processException(const XmlRpcMethodFaultException & e) + throw () +{ + Ptr::Ref message; + + if (e.getFaultCode() == 888) { + message = getResourceUstring("duplicateFileMsg"); + + } else { + message.reset(new const Glib::ustring(e.what())); + } + + std::cerr << e.what() << std::endl; + + return message; +} + diff --git a/campcaster/src/products/gLiveSupport/src/UploadFileWindow.h b/campcaster/src/products/gLiveSupport/src/UploadFileWindow.h index f39cbd51f..69be27d45 100644 --- a/campcaster/src/products/gLiveSupport/src/UploadFileWindow.h +++ b/campcaster/src/products/gLiveSupport/src/UploadFileWindow.h @@ -276,6 +276,17 @@ class UploadFileWindow : public GuiWindow void clearEverything(void) throw (); + /** + * Handle some known exception types. + * + * @param e the exception to be processed. + * @return a localized error message if e has one of the recognized + * faultCode values; e.what() if not. + */ + Ptr::Ref + processException(const XmlRpcMethodFaultException & e) + throw (); + protected: /** diff --git a/campcaster/src/products/gLiveSupport/var/root.txt b/campcaster/src/products/gLiveSupport/var/root.txt index 4a61920f7..f0dcecaf3 100644 --- a/campcaster/src/products/gLiveSupport/var/root.txt +++ b/campcaster/src/products/gLiveSupport/var/root.txt @@ -122,6 +122,8 @@ root:table unsupportedFileTypeMsg:string { "Unsupported file type." } missingTitleMsg:string { "Please enter a title." } badMetadataMsg:string { "Invalid data for {0}." } + duplicateFileMsg:string { "Error: the file is in the storage " + "already." } } simplePlaylistManagementWindow:table