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>
Cody Oss
2 years ago
177 | 177 | defer resp.Body.Close() |
178 | 178 | respBody, err := ioutil.ReadAll(resp.Body) |
179 | 179 | if err != nil { |
180 | return nil, fmt.Errorf("downscope: unable to read reaponse body: %v", err) | |
180 | return nil, fmt.Errorf("downscope: unable to read response body: %v", err) | |
181 | 181 | } |
182 | 182 | if resp.StatusCode != http.StatusOK { |
183 | b, err := ioutil.ReadAll(resp.Body) | |
184 | if err != nil { | |
185 | return nil, fmt.Errorf("downscope: unable to exchange token; %v. Failed to read response body: %v", resp.StatusCode, err) | |
186 | } | |
187 | return nil, fmt.Errorf("downscope: unable to exchange token; %v. Server responsed: %v", resp.StatusCode, string(b)) | |
183 | return nil, fmt.Errorf("downscope: unable to exchange token; %v. Server responded: %s", resp.StatusCode, respBody) | |
188 | 184 | } |
189 | 185 | |
190 | 186 | var tresp downscopedTokenResponse |