[gnome-online-accounts/gnome-3-8] Don't use technical jargon in user visible strings



commit 43e371366c87f1ecfae279c8360f3ad0bf0ac059
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Mar 11 19:05:13 2013 +0100

    Don't use technical jargon in user visible strings
    
    There is no point in telling the user about JSON and the names of the
    various members that we expect to find within it. For the user this is
    just our inability to parse the response.
    
    Detailed explanations with technical terms are better sent to the
    logs.
    
    Fixes: https://bugzilla.gnome.org/657761

 src/goabackend/goafacebookprovider.c    |   22 ++++++++++++++++++----
 src/goabackend/goaflickrprovider.c      |   28 ++++++++++++++++++++++------
 src/goabackend/goagoogleprovider.c      |   19 ++++++++++++++++---
 src/goabackend/goaoauth2provider.c      |   24 ++++++++++++++++++++----
 src/goabackend/goawindowsliveprovider.c |   22 ++++++++++++++++++----
 5 files changed, 94 insertions(+), 21 deletions(-)
---
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index 5327df4..b65bf8c 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -27,6 +27,7 @@
 #include <rest/rest-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
@@ -164,6 +165,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
                    GCancellable       *cancellable,
                    GError            **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -173,6 +175,8 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -208,9 +212,16 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -218,19 +229,21 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   id = g_strdup (json_object_get_string_member (json_object, "id"));
   if (id == NULL)
     {
+      goa_warning ("Did not find id in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find id member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "email"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find email in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find email member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -243,6 +256,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (parser != NULL)
diff --git a/src/goabackend/goaflickrprovider.c b/src/goabackend/goaflickrprovider.c
index 398ae4b..a472669 100644
--- a/src/goabackend/goaflickrprovider.c
+++ b/src/goabackend/goaflickrprovider.c
@@ -28,6 +28,7 @@
 #include <rest/oauth-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
@@ -140,6 +141,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
                    GCancellable      *cancellable,
                    GError           **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -149,6 +151,8 @@ get_identity_sync (GoaOAuthProvider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -186,9 +190,16 @@ get_identity_sync (GoaOAuthProvider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -196,37 +207,41 @@ get_identity_sync (GoaOAuthProvider  *provider,
   json_object = json_object_get_object_member (json_object, "user");
   if (json_object == NULL)
     {
+      goa_warning ("Did not find user in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   id = g_strdup (json_object_get_string_member (json_object, "id"));
   if (id == NULL)
     {
+      goa_warning ("Did not find user.id in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user.id member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   json_object = json_object_get_object_member (json_object, "username");
   if (json_object == NULL)
     {
+      goa_warning ("Did not find user.username in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user.username member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "_content"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find user.username._content in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user.username._content member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -239,6 +254,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (call != NULL)
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index fe4200f..3bc174b 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -27,6 +27,7 @@
 #include <rest/oauth-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
@@ -166,6 +167,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
                    GCancellable       *cancellable,
                    GError            **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -174,6 +176,8 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   gchar *email;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -203,9 +207,16 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -213,10 +224,11 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   email = g_strdup (json_object_get_string_member (json_object, "email"));
   if (email == NULL)
     {
+      goa_warning ("Did not find email in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find email member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -227,6 +239,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
     *out_presentation_identity = g_strdup (ret); /* for now: use email as presentation identity */
 
  out:
+  g_clear_error (&identity_error);
   g_free (email);
   if (call != NULL)
     g_object_unref (call);
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 4bc60fa..2f78f3f 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -519,6 +519,7 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
                  GCancellable       *cancellable,
                  GError            **error)
 {
+  GError *tokens_error;
   RestProxy *proxy;
   RestProxyCall *call;
   gchar *ret;
@@ -535,6 +536,8 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
   ret_access_token_expires_in = 0;
   ret_refresh_token = NULL;
 
+  tokens_error = NULL;
+
   proxy = rest_proxy_new (goa_oauth2_provider_get_token_uri (provider), FALSE);
   call = rest_proxy_new_call (proxy);
 
@@ -583,14 +586,18 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
     {
       GHashTable *hash;
       const gchar *expires_in_str;
+
+      goa_debug ("Response is not JSON - possibly old OAuth2 implementation");
+
       hash = soup_form_decode (payload);
       ret_access_token = g_strdup (g_hash_table_lookup (hash, "access_token"));
       if (ret_access_token == NULL)
         {
+          goa_warning ("Did not find access_token in non-JSON data");
           g_set_error (error,
                        GOA_ERROR,
                        GOA_ERROR_FAILED,
-                       _("Didn't find access_token in non-JSON data"));
+                       _("Could not parse response"));
           g_hash_table_unref (hash);
           goto out;
         }
@@ -611,9 +618,16 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
       JsonObject *object;
 
       parser = json_parser_new ();
-      if (!json_parser_load_from_data (parser, payload, payload_length, error))
+      if (!json_parser_load_from_data (parser, payload, payload_length, &tokens_error))
         {
-          g_prefix_error (error, _("Error parsing response as JSON: "));
+          goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                       tokens_error->message,
+                       g_quark_to_string (tokens_error->domain),
+                       tokens_error->code);
+          g_set_error (error,
+                       GOA_ERROR,
+                       GOA_ERROR_FAILED,
+                       _("Could not parse response"));
           g_object_unref (parser);
           goto out;
         }
@@ -621,10 +635,11 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
       ret_access_token = g_strdup (json_object_get_string_member (object, "access_token"));
       if (ret_access_token == NULL)
         {
+          goa_warning ("Did not find access_token in JSON data");
           g_set_error (error,
                        GOA_ERROR,
                        GOA_ERROR_FAILED,
-                       _("Didn't find access_token in JSON data"));
+                       _("Could not parse response"));
           goto out;
         }
       /* refresh_token is optional... */
@@ -646,6 +661,7 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
     }
 
  out:
+  g_clear_error (&tokens_error);
   g_free (ret_access_token);
   g_free (ret_refresh_token);
   if (call != NULL)
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index fd4299b..ed6e3d3 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -29,6 +29,7 @@
 #include <json-glib/json-glib.h>
 #include <webkit/webkit.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
@@ -151,6 +152,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
                    GCancellable       *cancellable,
                    GError            **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -160,6 +162,8 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -190,9 +194,16 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -200,10 +211,11 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   id = g_strdup (json_object_get_string_member (json_object, "id"));
   if (id == NULL)
     {
+      goa_warning ("Did not find id in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find id member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -211,10 +223,11 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "account"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find emails.account in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find account email member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -227,6 +240,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (call != NULL)


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