From 20978bf1f9d883e79689f9ca276052873bd23406 Mon Sep 17 00:00:00 2001
From: vikasrohit <vikas.agarwal@appirio.com>
Date: Wed, 4 Nov 2015 11:10:10 -0800
Subject: [PATCH 1/2] SUP-2311, Add generic error message when something fails
 while linking/unlinking the external account

-- Added generic error message when anything bad happens with link/unlink calls.
---
 .../external-account/external-account.directive.js   |  5 ++++-
 app/services/externalAccounts.service.js             | 12 +++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/app/directives/external-account/external-account.directive.js b/app/directives/external-account/external-account.directive.js
index 012e292cb..f3082565d 100644
--- a/app/directives/external-account/external-account.directive.js
+++ b/app/directives/external-account/external-account.directive.js
@@ -80,6 +80,9 @@
                     {provider: provider.displayName }
                   )
                 );
+              } else {
+                $log.error("Fatal Error: _link: " + resp.msg);
+                toaster.pop('error', "Whoops!", "Sorry, we are unable to add your account right now. Please try again later. If the problem persists, please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>.");
               }
             });
           }
@@ -107,7 +110,7 @@
                 $log.info("Social profile not linked to account");
                 msg = "{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>.";
               } else {
-                $log.info("Fatal error: " + msg);
+                $log.error("Fatal error: _unlink: " + msg);
                 msg = "Sorry! We are unable to unlink your {provider} account. If problem persists, please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>";
               }
               toaster.pop('error', "Whoops!", String.supplant(msg, {provider: provider.displayName }));
diff --git a/app/services/externalAccounts.service.js b/app/services/externalAccounts.service.js
index ad82a9d3d..e99f71a76 100644
--- a/app/services/externalAccounts.service.js
+++ b/app/services/externalAccounts.service.js
@@ -58,12 +58,10 @@
         })
         .catch(function(resp) {
           $log.error("Error unlinking account: " + resp.data.result.content);
-          var status = resp.status;
+          var status = "FATAL_ERROR";
           var msg = resp.data.result.content;
-          if (resp.status = 404) {
+          if (resp.status === 404) {
             status = "SOCIAL_PROFILE_NOT_EXIST";
-          } else {
-            status = "FATAL_ERROR"
           }
           $reject({
             status: status,
@@ -113,9 +111,13 @@
                   });
                 })
                 .catch(function(resp) {
+                  var errorStatus = "FATAL_ERROR";
                   $log.error("Error linking account: " + resp.data.result.content);
+                  if (resp.data.result && resp.data.result.status === 400) {
+                    errorStatus = "SOCIAL_PROFILE_ALREADY_EXISTS";
+                  }
                   reject({
-                    status: "SOCIAL_PROFILE_ALREADY_EXISTS",
+                    status: errorStatus,
                     msg: resp.data.result.content
                   });
                 });

From 6cc8a225a497ffc5f44be87ea4a77fb2f47ecb75 Mon Sep 17 00:00:00 2001
From: vikasrohit <vikas.agarwal@appirio.com>
Date: Wed, 4 Nov 2015 11:17:42 -0800
Subject: [PATCH 2/2] SUP-2311, Add generic error message when something fails
 while linking/unlinking the external account

-- Fixed support email address link and its text
---
 .../external-account/external-account.directive.js        | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/app/directives/external-account/external-account.directive.js b/app/directives/external-account/external-account.directive.js
index f3082565d..832a100d3 100644
--- a/app/directives/external-account/external-account.directive.js
+++ b/app/directives/external-account/external-account.directive.js
@@ -76,13 +76,13 @@
                 toaster.pop('error', "Whoops!",
                   String.supplant(
                     "This {provider} account is linked to another account. \
-                    If you think this is an error please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>.",
+                    If you think this is an error please contact <a href=\"mailTo:support@topcoder.com\">support@topcoder.com</a>.",
                     {provider: provider.displayName }
                   )
                 );
               } else {
                 $log.error("Fatal Error: _link: " + resp.msg);
-                toaster.pop('error', "Whoops!", "Sorry, we are unable to add your account right now. Please try again later. If the problem persists, please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>.");
+                toaster.pop('error', "Whoops!", "Sorry, we are unable to add your account right now. Please try again later. If the problem persists, please contact <a href=\"mailTo:support@topcoder.com\">support@topcoder.com</a>.");
               }
             });
           }
@@ -108,10 +108,10 @@
               var msg = resp.msg;
               if (resp.status === 'SOCIAL_PROFILE_NOT_EXIST') {
                 $log.info("Social profile not linked to account");
-                msg = "{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>.";
+                msg = "{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:support@topcoder.com\">support@topcoder.com</a>.";
               } else {
                 $log.error("Fatal error: _unlink: " + msg);
-                msg = "Sorry! We are unable to unlink your {provider} account. If problem persists, please contact <a href=\"mailTo:support@.appirio.com\">support@apprio.com</a>";
+                msg = "Sorry! We are unable to unlink your {provider} account. If problem persists, please contact <a href=\"mailTo:support@topcoder.com\">support@topcoder.com</a>";
               }
               toaster.pop('error', "Whoops!", String.supplant(msg, {provider: provider.displayName }));
             });