From c30da607cb5b27403e0416cd070e77effb2ad6b9 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Fri, 22 Feb 2019 22:27:53 -0500 Subject: [PATCH] oauth_twitter_callback.go: add better error handling --- api/oauth_twitter_callback.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/api/oauth_twitter_callback.go b/api/oauth_twitter_callback.go index f97d864..6689d3d 100644 --- a/api/oauth_twitter_callback.go +++ b/api/oauth_twitter_callback.go @@ -58,12 +58,28 @@ func twitterCallbackHandler(w http.ResponseWriter, r *http.Request) { return } - name := res["name"].(string) - handle := res["screen_name"].(string) - link := "https://twitter.com/" + handle - photo := "https://twitter.com/" + handle + "/profile_image" + if res["email"] == nil { + fmt.Fprintf(w, "Error: no email address returned by Twitter") + return + } + email := res["email"].(string) + if res["name"] == nil { + fmt.Fprintf(w, "Error: no name returned by Twitter") + return + } + + name := res["name"].(string) + + link := "undefined" + photo := "undefined" + if res["handle"] != nil { + handle := res["screen_name"].(string) + link = "https://twitter.com/" + handle + photo = "https://twitter.com/" + handle + "/profile_image" + } + c, err := commenterGetByEmail("twitter", email) if err != nil && err != errorNoSuchCommenter { fmt.Fprintf(w, "Error: %s", err.Error())