mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-19 14:15:25 +02:00
Fix abnormal termination when no internet connection (#643)
* Fix abnormal termination when no internet connection
This commit is contained in:
parent
90a28e0f6c
commit
0424caaaf8
|
@ -415,18 +415,22 @@ final class OneDriveApi
|
|||
private void acquireToken(const(char)[] postData)
|
||||
{
|
||||
JSONValue response = post(tokenUrl, postData);
|
||||
if ("access_token" in response){
|
||||
accessToken = "bearer " ~ response["access_token"].str();
|
||||
refreshToken = response["refresh_token"].str();
|
||||
accessTokenExpiration = Clock.currTime() + dur!"seconds"(response["expires_in"].integer());
|
||||
if (!.dryRun) {
|
||||
std.file.write(cfg.refreshTokenFilePath, refreshToken);
|
||||
if (response.type() == JSONType.object) {
|
||||
if ("access_token" in response){
|
||||
accessToken = "bearer " ~ response["access_token"].str();
|
||||
refreshToken = response["refresh_token"].str();
|
||||
accessTokenExpiration = Clock.currTime() + dur!"seconds"(response["expires_in"].integer());
|
||||
if (!.dryRun) {
|
||||
std.file.write(cfg.refreshTokenFilePath, refreshToken);
|
||||
}
|
||||
if (printAccessToken) writeln("New access token: ", accessToken);
|
||||
} else {
|
||||
log.error("\nInvalid authentication response from OneDrive. Please check the response uri\n");
|
||||
// re-authorize
|
||||
authorize();
|
||||
}
|
||||
if (printAccessToken) writeln("New access token: ", accessToken);
|
||||
} else {
|
||||
log.error("\nInvalid authentication response from OneDrive. Please check the response uri\n");
|
||||
// re-authorize
|
||||
authorize();
|
||||
log.vdebug("Invalid JSON response from OneDrive unable to initialize application");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -611,18 +615,18 @@ final class OneDriveApi
|
|||
if (.debugResponse){
|
||||
writeln("OneDrive HTTP Server Response: ", http.statusLine.code);
|
||||
}
|
||||
|
||||
return data.length;
|
||||
};
|
||||
|
||||
JSONValue json;
|
||||
try {
|
||||
http.perform();
|
||||
} catch (CurlException e) {
|
||||
// Potentially Timeout was reached on handle error
|
||||
log.error("\nThere was a problem in accessing the Microsoft OneDrive service - Internet connectivity issue?\n");
|
||||
log.error("ERROR: There was a timeout in accessing the Microsoft OneDrive service - Internet connectivity issue?");
|
||||
return json;
|
||||
}
|
||||
|
||||
JSONValue json;
|
||||
try {
|
||||
json = content.parseJSON();
|
||||
} catch (JSONException e) {
|
||||
|
|
Loading…
Reference in a new issue