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
This commit is contained in:
Christian Brunner
2017-06-16 14:06:14 +02:00
parent 169d6db544
commit 6a73a62591

View File

@@ -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
}
}