improve error reporting on OAuth2 user profile fetch
This commit is contained in:
		
							parent
							
								
									1095637bcd
								
							
						
					
					
						commit
						2dc000da65
					
				| 
						 | 
					@ -3,6 +3,7 @@ package auth
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,6 +121,16 @@ func (p *baseProvider) FetchRawUserData(token *oauth2.Token, result any) error {
 | 
				
			||||||
		return err
 | 
							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)
 | 
						return json.Unmarshal(content, &result)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue