This commit is contained in:
fgerlits 2007-01-16 12:53:55 +00:00
parent edeaf9cbd7
commit bf76d0f770
6 changed files with 121 additions and 11 deletions

View File

@ -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.
*

View File

@ -40,6 +40,8 @@
#include "configure.h"
#endif
#include <sstream>
#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;
}
};

View File

@ -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);
}
}

View File

@ -43,6 +43,7 @@
#include <fileref.h>
#include <audioproperties.h>
#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<Playlist>::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<const Glib::ustring>::Ref
UploadFileWindow :: processException(const XmlRpcMethodFaultException & e)
throw ()
{
Ptr<const Glib::ustring>::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;
}

View File

@ -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<const Glib::ustring>::Ref
processException(const XmlRpcMethodFaultException & e)
throw ();
protected:
/**

View File

@ -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