1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-01-09 01:17:51 +02:00

improve error reporting on OAuth2 user profile fetch

This commit is contained in:
Gani Georgiev 2022-07-15 18:52:37 +03:00
parent 1095637bcd
commit 2dc000da65

View File

@ -3,6 +3,7 @@ package auth
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
@ -120,6 +121,16 @@ func (p *baseProvider) FetchRawUserData(token *oauth2.Token, result any) error {
return err
}
// http.Client.Get doesn't treat non 2xx responses as error
if response.StatusCode >= 400 {
return fmt.Errorf(
"Failed to fetch OAuth2 user profile via %s (%d):\n%s",
p.userApiUrl,
response.StatusCode,
string(content),
)
}
return json.Unmarshal(content, &result)
}