Skip to content

Commit 9a536e3

Browse files
author
Diwaker Gupta
committed
Fix parsing for API errors for download RPCs.
Fixes #34 Fixes #35
1 parent 115c6b8 commit 9a536e3

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

dropbox/files/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,11 @@ func (dbx *apiImpl) Download(arg *DownloadArg) (res *FileMetadata, content io.Re
13731373
return
13741374
}
13751375
if resp.StatusCode == http.StatusConflict {
1376+
defer resp.Body.Close()
1377+
body, err = ioutil.ReadAll(resp.Body)
1378+
if err != nil {
1379+
return
1380+
}
13761381
var apiError DownloadAPIError
13771382
err = json.Unmarshal(body, &apiError)
13781383
if err != nil {
@@ -1524,6 +1529,11 @@ func (dbx *apiImpl) GetPreview(arg *PreviewArg) (res *FileMetadata, content io.R
15241529
return
15251530
}
15261531
if resp.StatusCode == http.StatusConflict {
1532+
defer resp.Body.Close()
1533+
body, err = ioutil.ReadAll(resp.Body)
1534+
if err != nil {
1535+
return
1536+
}
15271537
var apiError GetPreviewAPIError
15281538
err = json.Unmarshal(body, &apiError)
15291539
if err != nil {
@@ -1664,6 +1674,11 @@ func (dbx *apiImpl) GetThumbnail(arg *ThumbnailArg) (res *FileMetadata, content
16641674
return
16651675
}
16661676
if resp.StatusCode == http.StatusConflict {
1677+
defer resp.Body.Close()
1678+
body, err = ioutil.ReadAll(resp.Body)
1679+
if err != nil {
1680+
return
1681+
}
16671682
var apiError GetThumbnailAPIError
16681683
err = json.Unmarshal(body, &apiError)
16691684
if err != nil {

dropbox/paper/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ func (dbx *apiImpl) DocsDownload(arg *PaperDocExport) (res *PaperDocExportResult
285285
return
286286
}
287287
if resp.StatusCode == http.StatusConflict {
288+
defer resp.Body.Close()
289+
body, err = ioutil.ReadAll(resp.Body)
290+
if err != nil {
291+
return
292+
}
288293
var apiError DocsDownloadAPIError
289294
err = json.Unmarshal(body, &apiError)
290295
if err != nil {

dropbox/sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
hostAPI = "api"
3636
hostContent = "content"
3737
hostNotify = "notify"
38-
sdkVersion = "3.2.0"
38+
sdkVersion = "3.3.0"
3939
specVersion = "318810d"
4040
)
4141

dropbox/sharing/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,11 @@ func (dbx *apiImpl) GetSharedLinkFile(arg *GetSharedLinkMetadataArg) (res IsShar
10811081
return
10821082
}
10831083
if resp.StatusCode == http.StatusConflict {
1084+
defer resp.Body.Close()
1085+
body, err = ioutil.ReadAll(resp.Body)
1086+
if err != nil {
1087+
return
1088+
}
10841089
var apiError GetSharedLinkFileAPIError
10851090
err = json.Unmarshal(body, &apiError)
10861091
if err != nil {

generator/go_client.stoneg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,15 @@ def _generate_response(self, route):
176176

177177
def _generate_error_handling(self, route):
178178
out = self.emit
179+
style = route.attrs.get('style', 'rpc')
179180
with self.block('if resp.StatusCode == http.StatusConflict'):
181+
# If style was download, body was assigned to a header.
182+
# Need to re-read the response body to parse the error
183+
if style == 'download':
184+
out('defer resp.Body.Close()')
185+
with self.block('body, err = ioutil.ReadAll(resp.Body);'
186+
'if err != nil'):
187+
out('return')
180188
out('var apiError %sAPIError' % fmt_var(route.name))
181189
with self.block('err = json.Unmarshal(body, &apiError);'
182190
'if err != nil'):

0 commit comments

Comments
 (0)