Handling exceptions related to XML parser
This commit is contained in:
parent
c79af87410
commit
b297329ba3
2 changed files with 38 additions and 4 deletions
|
@ -382,12 +382,21 @@ void TwitterPlugin::directMessageResponse(std::string &user, std::vector<DirectM
|
|||
if(!messages.size()) return;
|
||||
|
||||
if(twitterMode == SINGLECONTACT) {
|
||||
std::string msglist = "\n***************MSG LIST****************\n";
|
||||
|
||||
std::string msglist = "";
|
||||
std::string msgID = getMostRecentDMID(user);
|
||||
std::string maxID = msgID;
|
||||
|
||||
for(int i=0 ; i < messages.size() ; i++) {
|
||||
msglist += " - " + messages[i].getSenderData().getScreenName() + ": " + messages[i].getMessage() + "\n";
|
||||
if(cmp(msgID, messages[i].getID()) == -1) {
|
||||
msglist += " - " + messages[i].getSenderData().getScreenName() + ": " + messages[i].getMessage() + "\n";
|
||||
if(cmp(maxID, messages[i].getID()) == -1) maxID = messages[i].getID();
|
||||
}
|
||||
}
|
||||
msglist += "***************************************\n";
|
||||
handleMessage(user, "twitter-account", msglist);
|
||||
|
||||
if(msglist.length()) handleMessage(user, "twitter-account", msglist);
|
||||
updateLastDMID(user, maxID);
|
||||
|
||||
} else if(twitterMode == MULTIPLECONTACT) {
|
||||
|
||||
std::string msgID = getMostRecentDMID(user);
|
||||
|
|
|
@ -67,6 +67,11 @@ std::vector<Status> getTimeline(std::string &xml)
|
|||
std::vector<Status> statuses;
|
||||
Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
|
||||
|
||||
if(rootElement == NULL) {
|
||||
LOG4CXX_ERROR(logger, "Error while parsing XML")
|
||||
return statuses;
|
||||
}
|
||||
|
||||
if(rootElement->getName() != "statuses") {
|
||||
LOG4CXX_ERROR(logger, "XML doesn't correspond to timeline")
|
||||
return statuses;
|
||||
|
@ -87,6 +92,11 @@ std::vector<DirectMessage> getDirectMessages(std::string &xml)
|
|||
std::vector<DirectMessage> DMs;
|
||||
Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
|
||||
|
||||
if(rootElement == NULL) {
|
||||
LOG4CXX_ERROR(logger, "Error while parsing XML")
|
||||
return DMs;
|
||||
}
|
||||
|
||||
if(rootElement->getName() != TwitterReponseTypes::directmessages) {
|
||||
LOG4CXX_ERROR(logger, "XML doesn't correspond to direct-messages")
|
||||
return DMs;
|
||||
|
@ -107,6 +117,11 @@ std::vector<User> getUsers(std::string &xml)
|
|||
std::vector<User> users;
|
||||
Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
|
||||
|
||||
if(rootElement == NULL) {
|
||||
LOG4CXX_ERROR(logger, "Error while parsing XML")
|
||||
return users;
|
||||
}
|
||||
|
||||
if(rootElement->getName() != TwitterReponseTypes::users) {
|
||||
LOG4CXX_ERROR(logger, "XML doesn't correspond to user list")
|
||||
return users;
|
||||
|
@ -127,6 +142,11 @@ std::vector<std::string> getIDs(std::string &xml)
|
|||
std::vector<std::string> IDs;
|
||||
Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
|
||||
|
||||
if(rootElement == NULL) {
|
||||
LOG4CXX_ERROR(logger, "Error while parsing XML")
|
||||
return IDs;
|
||||
}
|
||||
|
||||
if(rootElement->getName() != TwitterReponseTypes::id_list) {
|
||||
LOG4CXX_ERROR(logger, "XML doesn't correspond to id_list");
|
||||
return IDs;
|
||||
|
@ -146,6 +166,11 @@ std::string getErrorMessage(std::string &xml)
|
|||
std::string error;
|
||||
Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml);
|
||||
|
||||
if(rootElement == NULL) {
|
||||
LOG4CXX_ERROR(logger, "Error while parsing XML");
|
||||
return "";
|
||||
}
|
||||
|
||||
const std::string xmlns = rootElement->getNamespace();
|
||||
const Swift::ParserElement::ref errorElement = rootElement->getChild(TwitterReponseTypes::error, xmlns);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue