[libgdata] [youtube] Improved error handling when uploading videos



commit 31d0669d49abf1d1b0d605045d57687e12f4dda7
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Apr 24 22:18:44 2009 +0100

    [youtube] Improved error handling when uploading videos
    
    Improved error handling when uploading videos so that it didn't set GErrors
    on top of older GErrors. Also updated the test suite to be in-line with XML
    changes.
---
 gdata/services/youtube/gdata-youtube-service.c |   24 +++++++++++++++++++++---
 gdata/tests/youtube.c                          |    6 +++---
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/gdata/services/youtube/gdata-youtube-service.c b/gdata/services/youtube/gdata-youtube-service.c
index b45933f..b0d6302 100644
--- a/gdata/services/youtube/gdata-youtube-service.c
+++ b/gdata/services/youtube/gdata-youtube-service.c
@@ -258,17 +258,35 @@ parse_error_response (GDataService *self, guint status, const gchar *reason_phra
 		xmlChar *domain = NULL, *code = NULL, *location = NULL;
 		xmlNode *child_node = node->xmlChildrenNode;
 
+		if (node->type == XML_TEXT_NODE) {
+			/* Skip text nodes; they're all whitespace */
+			node = node->next;
+			continue;
+		}
+
 		/* Get the error data */
 		while (child_node != NULL) {
+			if (child_node->type == XML_TEXT_NODE) {
+				/* Skip text nodes; they're all whitespace */
+				child_node = child_node->next;
+				continue;
+			}
+
 			if (xmlStrcmp (child_node->name, (xmlChar*) "domain") == 0)
 				domain = xmlNodeListGetString (doc, child_node->xmlChildrenNode, TRUE);
 			else if (xmlStrcmp (child_node->name, (xmlChar*) "code") == 0)
 				code = xmlNodeListGetString (doc, child_node->xmlChildrenNode, TRUE);
 			else if (xmlStrcmp (child_node->name, (xmlChar*) "location") == 0)
 				location = xmlNodeListGetString (doc, child_node->xmlChildrenNode, TRUE);
-			else {
-				/* Unknown element */
-				gdata_parser_error_unhandled_element ((gchar*) child_node->ns->prefix, (gchar*) child_node->name, "error", error);
+			else if (xmlStrcmp (child_node->name, (xmlChar*) "internalReason") != 0) {
+				/* Unknown element (ignore internalReason) */
+				if (*error == NULL) {
+					gdata_parser_error_unhandled_element ((gchar*) child_node->ns->prefix, (gchar*) child_node->name,
+									      "error", error);
+				} else {
+					g_warning ("Unhandled <%s:%s> element as a child of <error>.", child_node->ns->prefix, child_node->name);
+				}
+
 				xmlFree (domain);
 				xmlFree (code);
 				xmlFree (location);
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index 1a99b3f..9048cc5 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -53,7 +53,7 @@ test_authentication (void)
 
 	/* Check all is as it should be */
 	g_assert (gdata_service_is_authenticated (service) == TRUE);
-	g_assert_cmpstr (gdata_service_get_username (service), ==, YT_USERNAME);
+	g_assert_cmpstr (gdata_service_get_username (service), ==, YT_USERNAME "@gmail.com");
 	g_assert_cmpstr (gdata_service_get_password (service), ==, YT_PASSWORD);
 	g_assert_cmpstr (gdata_youtube_service_get_youtube_user (GDATA_YOUTUBE_SERVICE (service)), ==, YT_USERNAME);
 }
@@ -73,7 +73,7 @@ test_authentication_async_cb (GDataService *service, GAsyncResult *async_result,
 
 	/* Check all is as it should be */
 	g_assert (gdata_service_is_authenticated (service) == TRUE);
-	g_assert_cmpstr (gdata_service_get_username (service), ==, YT_USERNAME);
+	g_assert_cmpstr (gdata_service_get_username (service), ==, YT_USERNAME "@gmail.com");
 	g_assert_cmpstr (gdata_service_get_password (service), ==, YT_PASSWORD);
 	g_assert_cmpstr (gdata_youtube_service_get_youtube_user (GDATA_YOUTUBE_SERVICE (service)), ==, YT_USERNAME);
 }
@@ -291,6 +291,7 @@ test_upload_simple (void)
 	g_assert_cmpstr (xml, ==,
 			 "<entry xmlns='http://www.w3.org/2005/Atom' "
 				"xmlns:media='http://search.yahoo.com/mrss/' "
+				"xmlns:gd='http://schemas.google.com/g/2005' "
 				"xmlns:yt='http://gdata.youtube.com/schemas/2007'>"
 			 	"<title type='text'>Bad Wedding Toast</title>"
 			 	"<media:group>"
@@ -298,7 +299,6 @@ test_upload_simple (void)
 			 		"<media:title type='plain'>Bad Wedding Toast</media:title>"
 			 		"<media:description type='plain'>I gave a bad toast at my friend&apos;s wedding.</media:description>"
 			 		"<media:keywords>toast, wedding</media:keywords>"
-			 		"<yt:duration seconds='0'/>"
 			 	"</media:group>"
 			 "</entry>");
 	g_free (xml);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]