Use NKError extension method in FileProviderEnumerator enumerate methods

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-13 14:27:17 +01:00
Родитель fdaf0d5aa5
Коммит 109258f3ce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: C839200C384636B0
1 изменённых файлов: 13 добавлений и 15 удалений

Просмотреть файл

@ -155,7 +155,13 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
guard readError == nil else {
NSLog("Finishing enumeration with error")
observer.finishEnumeratingWithError(readError!)
if let nkReadError = readError as? NKError {
observer.finishEnumeratingWithError(nkReadError.toFileProviderError())
} else {
observer.finishEnumeratingWithError(readError!)
}
return
}
@ -236,14 +242,14 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
NSLog("Finishing enumeration of changes with error")
if let nkReadError = readError as? NKError {
let nkErrorCode = nkReadError.errorCode
let fpError = nkReadError.toFileProviderError()
if nkErrorCode == 404 {
if nkReadError.errorCode == 404 {
NSLog("404 error means item no longer exists. Deleting metadata and reporting %@ as deletion without error", self.serverUrl)
guard let itemMetadata = self.enumeratedItemMetadata else {
NSLog("Invalid enumeratedItemMetadata, could not delete metadata nor report deletion")
observer.finishEnumeratingWithError(NSFileProviderError(.noSuchItem))
observer.finishEnumeratingWithError(fpError)
return
}
@ -255,19 +261,11 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
}
FileProviderEnumerator.completeChangesObserver(observer, anchor: anchor, ncKit: self.ncKit, newMetadatas: nil, updatedMetadatas: nil, deletedMetadatas: [itemMetadata])
} else if nkErrorCode == -9999 || nkErrorCode == -1001 || nkErrorCode == -1004 || nkErrorCode == -1005 || nkErrorCode == -1009 || nkErrorCode == -1012 || nkErrorCode == -1200 || nkErrorCode == -1202 || nkErrorCode == 500 || nkErrorCode == 503 || nkErrorCode == 200 {
// Provide something the file provider can do something with
observer.finishEnumeratingWithError(NSFileProviderError(.serverUnreachable))
return
} else if nkErrorCode == -1013 {
observer.finishEnumeratingWithError(NSFileProviderError(.notAuthenticated))
return
} else if nkErrorCode == 507 {
observer.finishEnumeratingWithError(NSFileProviderError(.insufficientQuota))
return
} else {
observer.finishEnumeratingWithError(NSFileProviderError(.cannotSynchronize))
}
observer.finishEnumeratingWithError(fpError)
return
}
observer.finishEnumeratingWithError(readError!)