[gnome-software] trivial: Improve the error message when downloading fails



commit e1cdafb6258b1fa2bfbd4a2c8d9a4327f6e6da8f
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jun 9 11:32:14 2016 +0100

    trivial: Improve the error message when downloading fails

 src/gs-plugin.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 4a19832..c0fce0c 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -819,7 +819,7 @@ gs_plugin_download_data (GsPlugin *plugin,
        guint status_code;
        g_autoptr(SoupMessage) msg = NULL;
 
-       g_debug ("downloading %s from %s", uri, priv->name);
+       g_debug ("downloading %s from plugin %s", uri, priv->name);
        msg = soup_message_new (SOUP_METHOD_GET, uri);
        if (app != NULL) {
                helper.plugin = plugin;
@@ -831,11 +831,17 @@ gs_plugin_download_data (GsPlugin *plugin,
        }
        status_code = soup_session_send_message (priv->soup_session, msg);
        if (status_code != SOUP_STATUS_OK) {
+               g_autoptr(GString) str = g_string_new (NULL);
+               g_string_append (str, soup_status_get_phrase (status_code));
+               if (msg->response_body->data != NULL) {
+                       g_string_append (str, ": ");
+                       g_string_append (str, msg->response_body->data);
+               }
                g_set_error (error,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,
-                            "failed to get shell extensions: %s",
-                            msg->response_body->data);
+                            "failed to download %s: %s",
+                            uri, str->str);
                return NULL;
        }
        return g_bytes_new (msg->response_body->data,
@@ -869,7 +875,7 @@ gs_plugin_download_file (GsPlugin *plugin,
        g_autoptr(GError) error_local = NULL;
        g_autoptr(SoupMessage) msg = NULL;
 
-       g_debug ("downloading %s to %s from %s", uri, filename, priv->name);
+       g_debug ("downloading %s to %s from plugin %s", uri, filename, priv->name);
        msg = soup_message_new (SOUP_METHOD_GET, uri);
        if (app != NULL) {
                helper.plugin = plugin;
@@ -881,12 +887,18 @@ gs_plugin_download_file (GsPlugin *plugin,
        }
        status_code = soup_session_send_message (priv->soup_session, msg);
        if (status_code != SOUP_STATUS_OK) {
+               g_autoptr(GString) str = g_string_new (NULL);
+               g_string_append (str, soup_status_get_phrase (status_code));
+               if (msg->response_body->data != NULL) {
+                       g_string_append (str, ": ");
+                       g_string_append (str, msg->response_body->data);
+               }
                g_set_error (error,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,
-                            "failed to get shell extensions: %s",
-                            msg->response_body->data);
-               return FALSE;
+                            "failed to download %s: %s",
+                            uri, str->str);
+               return NULL;
        }
        if (!g_file_set_contents (filename,
                                  msg->response_body->data,
@@ -895,7 +907,7 @@ gs_plugin_download_file (GsPlugin *plugin,
                g_set_error (error,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,
-                            "Failed to save firmware: %s",
+                            "Failed to save file: %s",
                             error_local->message);
                return FALSE;
        }


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