error handling
This commit is contained in:
parent
d5e1dfff61
commit
89bcd1a0c3
2 changed files with 17 additions and 12 deletions
|
@ -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")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue