error handling

This commit is contained in:
Livio Amstutz 2019-12-02 16:15:59 +01:00
parent d5e1dfff61
commit 89bcd1a0c3
2 changed files with 17 additions and 12 deletions

View file

@ -124,12 +124,16 @@ func (p *DefaultRP) CodeExchangeHandler(callback func(http.ResponseWriter, *http
http.Error(w, "failed to get state: "+err.Error(), http.StatusUnauthorized)
return
}
tokens, err := p.CodeExchange(r.Context(), r.URL.Query().Get("code"))
if err != nil {
http.Error(w, "failed to exchange token: "+err.Error(), http.StatusUnauthorized)
return
params := r.URL.Query()
if params.Get("code") != "" {
tokens, err := p.CodeExchange(r.Context(), params.Get("code"))
if err != nil {
http.Error(w, "failed to exchange token: "+err.Error(), http.StatusUnauthorized)
return
}
callback(w, r, tokens, state)
}
callback(w, r, tokens, state)
w.Write([]byte(params.Get("error")))
}
}