From 2bc19b11175fd0ae72c59c53fa45eff3f93d6a46 Mon Sep 17 00:00:00 2001 From: Cody Oss Date: Thu, 19 Aug 2021 13:00:08 -0600 Subject: [PATCH] google/downscope: return body in error message Change-Id: Ic424a95895668c2f37ffdcea2e3012e4c929cbe5 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/343689 Reviewed-by: Tyler Bui-Palsulich Trust: Tyler Bui-Palsulich Trust: Cody Oss Run-TryBot: Cody Oss TryBot-Result: Go Bot --- google/downscope/downscoping.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/google/downscope/downscoping.go b/google/downscope/downscoping.go index ac5c00d..3d4b553 100644 --- a/google/downscope/downscoping.go +++ b/google/downscope/downscoping.go @@ -178,14 +178,10 @@ func (dts downscopingTokenSource) Token() (*oauth2.Token, error) { defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("downscope: unable to read reaponse body: %v", err) + return nil, fmt.Errorf("downscope: unable to read response body: %v", err) } if resp.StatusCode != http.StatusOK { - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("downscope: unable to exchange token; %v. Failed to read response body: %v", resp.StatusCode, err) - } - return nil, fmt.Errorf("downscope: unable to exchange token; %v. Server responsed: %v", resp.StatusCode, string(b)) + return nil, fmt.Errorf("downscope: unable to exchange token; %v. Server responded: %s", resp.StatusCode, respBody) } var tresp downscopedTokenResponse