oauth_twitter_callback.go: add better error handling

This commit is contained in:
Adhityaa Chandrasekar 2019-02-22 22:27:53 -05:00
parent be197f2b69
commit c30da607cb

View File

@ -58,12 +58,28 @@ func twitterCallbackHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
name := res["name"].(string) if res["email"] == nil {
handle := res["screen_name"].(string) fmt.Fprintf(w, "Error: no email address returned by Twitter")
link := "https://twitter.com/" + handle return
photo := "https://twitter.com/" + handle + "/profile_image" }
email := res["email"].(string) 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) c, err := commenterGetByEmail("twitter", email)
if err != nil && err != errorNoSuchCommenter { if err != nil && err != errorNoSuchCommenter {
fmt.Fprintf(w, "Error: %s", err.Error()) fmt.Fprintf(w, "Error: %s", err.Error())