コード例 #1
0
        private void LogAuthError(Exception e)
        {
            if (e == null)
            {
                return;
            }
            if (e.Message.Contains("Unable to fetch from"))
            {
                //return;
            }

            GlobalApplication.LogException(e);
        }
コード例 #2
0
        public ActionResult ErrorTestPage()
        {
            GlobalApplication.LogException(new Exception("Test Exception via GlobalApplication.LogException()"));

            throw new NotImplementedException("I AM IMPLEMENTED, I WAS BORN TO THROW ERRORS!");
        }
コード例 #3
0
        private ActionResult FetchFromGoogle(string accessToken)
        {
            string    result        = null;
            Exception lastException = null;

            for (var retry = 0; retry < GoogleAuthRetryAttempts; retry++)
            {
                try
                {
                    var url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessToken;
                    using (var wc = new WebClient())
                    {
                        result = wc.DownloadString(url);
                        if (result.HasValue())
                        {
                            break;
                        }
                    }
                }
                catch (WebException e)
                {
                    using (var reader = new StreamReader(e.Response.GetResponseStream()))
                    {
                        var text = reader.ReadToEnd();
                        LogAuthError(new Exception("Error fetching from google: " + text));
                    }
                    continue;
                }
                catch (Exception e)
                {
                    lastException = e;
                }
                if (retry == GoogleAuthRetryAttempts - 1)
                {
                    LogAuthError(lastException);
                }
            }

            if (result.IsNullOrEmpty() || result == "false")
            {
                return(LoginError("Error accessing Google account"));
            }

            try
            {
                var person = JsonConvert.DeserializeObject <GooglePerson>(result);

                if (person == null)
                {
                    return(LoginError("Error fetching user from Google"));
                }
                if (person.email == null)
                {
                    return(LoginError("Error fetching email from Google"));
                }

                return(LoginViaEmail(person.email, person.name, "/"));
            }
            catch (Exception e)
            {
                GlobalApplication.LogException(new Exception("Error in parsing google response: " + result, e));
                return(LoginError("There was an error fetching your account from Google.  Please try logging in again"));
            }
        }