From 6a73a62591389687add7ad79bd681070b0d240a2 Mon Sep 17 00:00:00 2001 From: Christian Brunner Date: Fri, 16 Jun 2017 14:06:14 +0200 Subject: [PATCH] Move error parsing behind status code handling Otherwise request throttling won't work and you will get errors like this: PUT https://api.onedrive.com/v1.0/drive/root:/dup/chunks/91xxx08:/content Failed to upload the chunk 91xxx08: 503 Unexpected response --- src/duplicacy_oneclient.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/duplicacy_oneclient.go b/src/duplicacy_oneclient.go index 7f24e99..99eb6b8 100644 --- a/src/duplicacy_oneclient.go +++ b/src/duplicacy_oneclient.go @@ -128,12 +128,6 @@ func (client *OneDriveClient) call(url string, method string, input interface{}, Error: OneDriveError { Status: response.StatusCode }, } - if err := json.NewDecoder(response.Body).Decode(errorResponse); err != nil { - return nil, 0, OneDriveError { Status: response.StatusCode, Message: fmt.Sprintf("Unexpected response"), } - } - - errorResponse.Error.Status = response.StatusCode - if response.StatusCode == 401 { if url == OneDriveRefreshTokenURL { @@ -152,6 +146,12 @@ func (client *OneDriveClient) call(url string, method string, input interface{}, backoff *= 2 continue } else { + if err := json.NewDecoder(response.Body).Decode(errorResponse); err != nil { + return nil, 0, OneDriveError { Status: response.StatusCode, Message: fmt.Sprintf("Unexpected response"), } + } + + errorResponse.Error.Status = response.StatusCode + return nil, 0, errorResponse.Error } }