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 <tbp@google.com>
Trust: Tyler Bui-Palsulich <tbp@google.com>
Trust: Cody Oss <codyoss@google.com>
Run-TryBot: Cody Oss <codyoss@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
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 @@
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