refactor: make error handling simpler (#55)

This commit is contained in:
Stavros
2025-03-19 16:41:19 +02:00
committed by GitHub
parent f3471880ee
commit 3ccc831a1f
15 changed files with 145 additions and 139 deletions

View File

@@ -15,21 +15,21 @@ type GenericUserInfoResponse struct {
func GetGenericEmail(client *http.Client, url string) (string, error) {
// Using the oauth client get the user info url
res, resErr := client.Get(url)
res, err := client.Get(url)
// Check if there was an error
if resErr != nil {
return "", resErr
if err != nil {
return "", err
}
log.Debug().Msg("Got response from generic provider")
// Read the body of the response
body, bodyErr := io.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
// Check if there was an error
if bodyErr != nil {
return "", bodyErr
if err != nil {
return "", err
}
log.Debug().Msg("Read body from generic provider")
@@ -38,11 +38,11 @@ func GetGenericEmail(client *http.Client, url string) (string, error) {
var user GenericUserInfoResponse
// Unmarshal the body into the user struct
jsonErr := json.Unmarshal(body, &user)
err = json.Unmarshal(body, &user)
// Check if there was an error
if jsonErr != nil {
return "", jsonErr
if err != nil {
return "", err
}
log.Debug().Msg("Parsed user from generic provider")