mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-03 23:55:44 +00:00 
			
		
		
		
	refactor: make error handling simpler
This commit is contained in:
		@@ -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")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user