Commit e8003c0e authored by A. Wilcox's avatar A. Wilcox

Allow display of all errors from eBay.

Each error is separated by \n\n.  You can use this format to cherry-pick
the errors, or just display them as-is.  Same API (getLastError).
parent 783cbcb3
......@@ -28,30 +28,63 @@ const char *EBAY_ITEM_FIELDS = "Item.ItemID,Item.Description,Item.StartPrice,Ite
const char *EBAY_ITEM_ARRAY_FIELDS = "ItemArray.Item.ItemID,ItemArray.Item.Description,ItemArray.Item.StartPrice,ItemArray.Item.BuyItNowPrice,ItemArray.Item.ListingDetails.EndTime,ItemArray.Item.SellingStatus.CurrentPrice,ItemArray.Item.SellingStatus.ConvertedCurrentPrice,ItemArray.Item.SellingStatus.BidCount,ItemArray.Item.SellingStatus.HighBidder,ItemArray.Item.SellingStatus.HighBidder,ItemArray.Item.ListingType,ItemArray.Item.SellingStatus.SoldAsBin,ItemArray.Item.ShippingDetails.ShippingServiceOptions,ItemArray.Item.PictureDetails,ItemArray.Item.Seller.UserID,ItemArray.Item.Subtitle,ItemArray.Item.Title,ItemArray.Item.HitCount,ItemArray.Item.WatchCount,ItemArray.Item.Location,ItemArray.Item.ConditionDisplayName,ItemArray.Item.ItemSpecifics,ItemArray.Item.PrimaryCategory.CategoryID,ItemArray.Item.ReturnPolicy,PaginationResult,PaginationOutput";
const char *getErrorFromXml(xmlDocPtr xml_doc)
char *getErrorFromXml(xmlDocPtr xml_doc)
{
xmlNodePtr errors_node = NULL;
errors_node = findNodeByName(xml_doc->children, "Errors");
if(errors_node != NULL || (errors_node = findNodeByName(xml_doc->children, "errorMessage")) != NULL)
char *message = NULL;
size_t message_len = 1;
for(xmlNodePtr error_node = findNodeByName(xml_doc->children, "Errors"); error_node; error_node = fastNodeByName(error_node, "Errors"))
{
xmlNodePtr error_node = NULL;
error_node = findNodeByName(errors_node, "Error");
if(error_node == NULL) error_node = errors_node;
xmlNodePtr message_node = NULL;
message_node = findNodeByName(error_node, "LongMessage");
if(message_node == NULL)
{
message_node = findNodeByName(error_node, "ShortMessage");
if(message_node == NULL)
message_node = findNodeByName(error_node, "message");
}
if(message_node != NULL)
{
return xml_to_char(message_node->children->content);
char *curr_message = xml_to_char(message_node->children->content);
size_t old_len;
if(message_len == 1) old_len = 0;
else old_len = message_len - 1;
message_len += strlen(curr_message) + 2;
message = static_cast<char *>(realloc(message, message_len));
sprintf(message + old_len, "%s\n\n", curr_message);
}
}
return "Invalid ACK";
if((errors_node = findNodeByName(xml_doc->children, "errorMessage")) != NULL)
{
xmlNodePtr message_node = findNodeByName(errors_node, "message");
if(message_node != NULL)
{
char *curr_message = xml_to_char(message_node->children->content);
size_t old_len;
if(message_len == 0) old_len = 0;
else old_len = message_len - 1;
message_len += strlen(curr_message) + 2;
message = static_cast<char *>(realloc(message, message_len));
sprintf(message + old_len, "%s\n", curr_message);
}
}
if(message == NULL)
{
return strdup("Invalid ACK");
}
else
{
// Remove the last \n
message[message_len - 2] = '\0';
return message;
}
}
inline bool IsAckSuccess(xmlDocPtr doc)
......@@ -72,11 +105,12 @@ inline bool IsAckSuccess(xmlDocPtr doc)
{
if(strcasecmp("Warning", xml_to_char(check->content)) == 0)
{
const char *warning = getErrorFromXml(doc);
char *warning = getErrorFromXml(doc);
// This fixes an annoying little thing where eBay is too
// stupid to deprecate their own warnings from 2008.
if(strstr(warning, "the token-based REST API") == NULL)
warning_error(getErrorFromXml(doc));
warning_error(warning);
free(warning);
return true;
}
return false;
......@@ -766,7 +800,7 @@ xmlDocPtr eBaySite::performOperationCore(WTConnection *connection, xmlDocPtr in_
{
fprintf(stderr, "Invalid ACK: %s\n", response);
this->error = strdup(getErrorFromXml(xml_doc));
this->error = getErrorFromXml(xml_doc);
xmlFreeDoc(xml_doc);
xml_doc = NULL;
......
......@@ -452,7 +452,7 @@ inline void setPaginationValues(xmlNodePtr for_node, AuPagedResult<T> *on_result
type of service, or NULL if the parameters were invalid.
*/
xmlNodePtr makePaginationNode(int items_per_page, int page, bool soa = false);
const char *getErrorFromXml(xmlDocPtr xml_doc);
char *getErrorFromXml(xmlDocPtr xml_doc);
typedef pair< eBayItem *, vector<eBayBestOffer> > ItemOfferPair;
......
......@@ -1128,7 +1128,9 @@ libAPI char *eBaySite::uploadPicture(const void *pic_data, size_t pic_size)
{
if(strcasecmp("Warning", xml_to_char(check->content)) == 0)
{
warning_error(getErrorFromXml(resp_xml));
char *warning = getErrorFromXml(resp_xml);
warning_error(warning);
free(warning);
ack = true;
}
else
......@@ -1142,7 +1144,7 @@ libAPI char *eBaySite::uploadPicture(const void *pic_data, size_t pic_size)
{
fprintf(stderr, "Invalid ACK: %s\n", response);
this->error = strdup(getErrorFromXml(resp_xml));
this->error = getErrorFromXml(resp_xml);
xmlFreeDoc(resp_xml);
resp_xml = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment