Skip to content
Permalink
Browse files

fix(all): use CheckResponse for media downloads (#773)

If a method supports media downloads use CheckResponse. This method
provided extra context to errors if the api follow
https://google.aip.dev/193. The storage api will continue to use
CheckMediaResponse as it does not conform to the aip due to legacy
reasons.

Fixes: #752
  • Loading branch information
codyoss committed Dec 11, 2020
1 parent b4a3262 commit 39cbab06d28f1d017bfc016c6735f6f45c51c90e
@@ -4379,7 +4379,7 @@ func (c *AccountsReportsGenerateCall) Download(opts ...googleapi.CallOption) (*h
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -7719,7 +7719,7 @@ func (c *ReportsGenerateCall) Download(opts ...googleapi.CallOption) (*http.Resp
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -12451,7 +12451,7 @@ func (c *SystemapksVariantsDownloadCall) Download(opts ...googleapi.CallOption)
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -2031,7 +2031,7 @@ func (c *MediaDownloadCall) Download(opts ...googleapi.CallOption) (*http.Respon
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -2059,7 +2059,7 @@ func (c *ReportsGetFileCall) Download(opts ...googleapi.CallOption) (*http.Respo
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -8907,7 +8907,7 @@ func (c *FilesExportCall) Download(opts ...googleapi.CallOption) (*http.Response
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -9267,7 +9267,7 @@ func (c *FilesGetCall) Download(opts ...googleapi.CallOption) (*http.Response, e
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -11721,7 +11721,7 @@ func (c *FilesWatchCall) Download(opts ...googleapi.CallOption) (*http.Response,
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -6715,7 +6715,7 @@ func (c *FilesExportCall) Download(opts ...googleapi.CallOption) (*http.Response
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -7049,7 +7049,7 @@ func (c *FilesGetCall) Download(opts ...googleapi.CallOption) (*http.Response, e
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -7981,7 +7981,7 @@ func (c *FilesWatchCall) Download(opts ...googleapi.CallOption) (*http.Response,
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -10211,7 +10211,7 @@ func (c *RevisionsGetCall) Download(opts ...googleapi.CallOption) (*http.Respons
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -2099,7 +2099,11 @@ func (meth *Method) generateCode() {
pn(`gensupport.SetOptions(c.urlParams_, opts...)`)
pn(`res, err := c.doRequest("media")`)
pn("if err != nil { return nil, err }")
pn("if err := googleapi.CheckMediaResponse(res); err != nil {")
if meth.api.Name == "storage" {
pn("if err := googleapi.CheckMediaResponse(res); err != nil {")
} else {
pn("if err := googleapi.CheckResponse(res); err != nil {")
}
pn("res.Body.Close()")
pn("return nil, err")
pn("}")
@@ -3379,7 +3379,7 @@ func (c *MediaDownloadCall) Download(opts ...googleapi.CallOption) (*http.Respon
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -10883,7 +10883,7 @@ func (c *CaptionsDownloadCall) Download(opts ...googleapi.CallOption) (*http.Res
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}
@@ -2131,7 +2131,7 @@ func (c *MediaDownloadCall) Download(opts ...googleapi.CallOption) (*http.Respon
if err != nil {
return nil, err
}
if err := googleapi.CheckMediaResponse(res); err != nil {
if err := googleapi.CheckResponse(res); err != nil {
res.Body.Close()
return nil, err
}

0 comments on commit 39cbab0

Please sign in to comment.