From 615aa05b42004c3a0f01d401a1e6ca2674dbea75 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 9 Apr 2021 06:21:01 +1000 Subject: [PATCH] Fix an unhandled Error 412 when uploading modified files to OneDrive Business Accounts (#1394) * Update error 412 handling when uploading modified files to OneDrive Business Accounts --- src/sync.d | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/sync.d b/src/sync.d index 0879f0db..5b825ecd 100644 --- a/src/sync.d +++ b/src/sync.d @@ -3425,7 +3425,7 @@ final class SyncEngine // HTTP request returned status code 412 - ETag does not match current item's value // Delete record from the local database - file will be uploaded as a new file writeln("skipped."); - log.vdebug("Simple Upload Replace Failed - OneDrive eTag / cTag match issue"); + log.vdebug("Simple Upload Replace Failed - OneDrive eTag / cTag match issue (Personal Account)"); log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file."); itemdb.deleteById(item.driveId, item.id); uploadFailed = true; @@ -3468,7 +3468,7 @@ final class SyncEngine // HTTP request returned status code 412 - ETag does not match current item's value // Delete record from the local database - file will be uploaded as a new file writeln("skipped."); - log.vdebug("Simple Upload Replace Failed - OneDrive eTag / cTag match issue"); + log.vdebug("Session Upload Replace Failed - OneDrive eTag / cTag match issue (Personal Account)"); log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file."); itemdb.deleteById(item.driveId, item.id); uploadFailed = true; @@ -3539,6 +3539,16 @@ final class SyncEngine log.fileOnly(path, " is currently checked out or locked for editing by another user."); uploadFailed = true; return; + } + if (e.httpStatusCode == 412) { + // HTTP request returned status code 412 - ETag does not match current item's value + // Delete record from the local database - file will be uploaded as a new file + writeln("skipped."); + log.vdebug("Session Upload Replace Failed - OneDrive eTag / cTag match issue (Business Account)"); + log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file."); + itemdb.deleteById(item.driveId, item.id); + uploadFailed = true; + return; } else { // display what the error is writeln("skipped."); @@ -3727,7 +3737,7 @@ final class SyncEngine log.vlog("OneDrive returned a 'HTTP 401 - Unauthorized' - gracefully handling error"); uploadFailed = true; return response; - } + } // Resolve https://github.com/abraunegg/onedrive/issues/36 if ((e.httpStatusCode == 409) || (e.httpStatusCode == 423)) { // The file is currently checked out or locked for editing by another user @@ -3738,6 +3748,16 @@ final class SyncEngine log.fileOnly(path, " is currently checked out or locked for editing by another user."); uploadFailed = true; return response; + } + if (e.httpStatusCode == 412) { + // HTTP request returned status code 412 - ETag does not match current item's value + // Delete record from the local database - file will be uploaded as a new file + writeln("skipped."); + log.vdebug("Session Upload Replace Failed - OneDrive eTag / cTag match issue (Sharepoint Library)"); + log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file."); + itemdb.deleteById(item.driveId, item.id); + uploadFailed = true; + return response; } else { // display what the error is writeln("skipped.");