зеркало из https://github.com/nextcloud/desktop.git
Make NKError extension code more Swift-like, clean up
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Родитель
f37e7cc3b6
Коммит
ebf96e3e81
|
@ -18,61 +18,48 @@ import NextcloudKit
|
|||
|
||||
extension NKError {
|
||||
static var noChangesErrorCode: Int {
|
||||
get {
|
||||
return -200
|
||||
}
|
||||
return -200
|
||||
}
|
||||
|
||||
var isCouldntConnectError: Bool {
|
||||
get {
|
||||
let nkErrorCode = self.errorCode
|
||||
return nkErrorCode == -9999 ||
|
||||
nkErrorCode == -1001 ||
|
||||
nkErrorCode == -1004 ||
|
||||
nkErrorCode == -1005 ||
|
||||
nkErrorCode == -1009 ||
|
||||
nkErrorCode == -1012 ||
|
||||
nkErrorCode == -1200 ||
|
||||
nkErrorCode == -1202 ||
|
||||
nkErrorCode == 500 ||
|
||||
nkErrorCode == 503 ||
|
||||
nkErrorCode == 200
|
||||
}
|
||||
return errorCode == -9999 ||
|
||||
errorCode == -1001 ||
|
||||
errorCode == -1004 ||
|
||||
errorCode == -1005 ||
|
||||
errorCode == -1009 ||
|
||||
errorCode == -1012 ||
|
||||
errorCode == -1200 ||
|
||||
errorCode == -1202 ||
|
||||
errorCode == 500 ||
|
||||
errorCode == 503 ||
|
||||
errorCode == 200
|
||||
}
|
||||
|
||||
var isUnauthenticatedError: Bool {
|
||||
get {
|
||||
return self.errorCode == -1013
|
||||
}
|
||||
return errorCode == -1013
|
||||
}
|
||||
|
||||
var isGoingOverQuotaError: Bool {
|
||||
get {
|
||||
return self.errorCode == 507
|
||||
}
|
||||
return errorCode == 507
|
||||
}
|
||||
|
||||
var isNotFoundError: Bool {
|
||||
get {
|
||||
return self.errorCode == 404
|
||||
}
|
||||
return errorCode == 404
|
||||
}
|
||||
|
||||
var isNoChangesError: Bool {
|
||||
get {
|
||||
return self.errorCode == NKError.noChangesErrorCode
|
||||
}
|
||||
return errorCode == NKError.noChangesErrorCode
|
||||
}
|
||||
|
||||
func toFileProviderError() -> NSFileProviderError {
|
||||
if self.isNotFoundError {
|
||||
var fileProviderError: NSFileProviderError {
|
||||
if isNotFoundError {
|
||||
return NSFileProviderError(.noSuchItem)
|
||||
} else if self.isCouldntConnectError {
|
||||
} else if isCouldntConnectError {
|
||||
// Provide something the file provider can do something with
|
||||
return NSFileProviderError(.serverUnreachable)
|
||||
} else if self.isUnauthenticatedError {
|
||||
} else if isUnauthenticatedError {
|
||||
return NSFileProviderError(.notAuthenticated)
|
||||
} else if self.isGoingOverQuotaError {
|
||||
} else if isGoingOverQuotaError {
|
||||
return NSFileProviderError(.insufficientQuota)
|
||||
} else {
|
||||
return NSFileProviderError(.cannotSynchronize)
|
||||
|
|
|
@ -115,7 +115,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
Logger.enumeration.error("Finishing enumeration for user: \(self.ncAccount.ncKitAccount, privacy: OSLogPrivacy.auto(mask: .hash)) with serverUrl: \(self.serverUrl, privacy: OSLogPrivacy.auto(mask: .hash)) with error \(readError!.localizedDescription, privacy: .public)")
|
||||
|
||||
let nkReadError = NKError(error: readError!)
|
||||
observer.finishEnumeratingWithError(nkReadError.toFileProviderError())
|
||||
observer.finishEnumeratingWithError(nkReadError.fileProviderError)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
|
||||
guard error == nil else {
|
||||
Logger.enumeration.info("Finished recursive change enumeration of working set for user: \(self.ncAccount.ncKitAccount, privacy: OSLogPrivacy.auto(mask: .hash)) with error: \(error!.errorDescription, privacy: .public)")
|
||||
observer.finishEnumeratingWithError(error!.toFileProviderError())
|
||||
observer.finishEnumeratingWithError(error!.fileProviderError)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
Logger.enumeration.error("Finishing enumeration of changes for user: \(self.ncAccount.ncKitAccount, privacy: OSLogPrivacy.auto(mask: .hash)) with serverUrl: \(self.serverUrl, privacy: OSLogPrivacy.auto(mask: .hash)) with error: \(readError!.localizedDescription, privacy: .public)")
|
||||
|
||||
let nkReadError = NKError(error: readError!)
|
||||
let fpError = nkReadError.toFileProviderError()
|
||||
let fpError = nkReadError.fileProviderError
|
||||
|
||||
if nkReadError.isNotFoundError {
|
||||
Logger.enumeration.info("404 error means item no longer exists. Deleting metadata and reporting \(self.serverUrl, privacy: OSLogPrivacy.auto(mask: .hash)) as deletion without error")
|
||||
|
|
|
@ -191,7 +191,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
|
||||
dbManager.addItemMetadata(updatedMetadata)
|
||||
|
||||
completionHandler(nil, nil, error.toFileProviderError())
|
||||
completionHandler(nil, nil, error.fileProviderError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
self.ncKit.createFolder(serverUrlFileName: newServerUrlFileName) { account, ocId, _, error in
|
||||
guard error == .success else {
|
||||
Logger.fileTransfer.error("Could not create new folder with name: \(itemTemplate.filename, privacy: .public), received error: \(error.errorDescription, privacy: .public)")
|
||||
completionHandler(itemTemplate, [], false, error.toFileProviderError())
|
||||
completionHandler(itemTemplate, [], false, error.fileProviderError)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
}) { account, ocId, etag, date, size, _, _, error in
|
||||
guard error == .success, let ocId = ocId else {
|
||||
Logger.fileTransfer.error("Could not upload item with filename: \(itemTemplate.filename, privacy: OSLogPrivacy.auto(mask: .hash)), received error: \(error.errorDescription, privacy: .public)")
|
||||
completionHandler(itemTemplate, [], false, error.toFileProviderError())
|
||||
completionHandler(itemTemplate, [], false, error.fileProviderError)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
overwrite: false) { account, error in
|
||||
guard error == .success else {
|
||||
Logger.fileTransfer.error("Could not move file or folder: \(oldServerUrlFileName, privacy: OSLogPrivacy.auto(mask: .hash)) to \(newServerUrlFileName, privacy: OSLogPrivacy.auto(mask: .hash)), received error: \(error.errorDescription, privacy: .public)")
|
||||
renameError = error.toFileProviderError()
|
||||
renameError = error.fileProviderError
|
||||
moveFileOrFolderDispatchGroup.leave()
|
||||
return
|
||||
}
|
||||
|
@ -529,7 +529,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
|
||||
dbManager.addItemMetadata(metadata)
|
||||
|
||||
completionHandler(modifiedItem, [], false, error.toFileProviderError())
|
||||
completionHandler(modifiedItem, [], false, error.fileProviderError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
|||
self.ncKit.deleteFileOrFolder(serverUrlFileName: serverFileNameUrl) { account, error in
|
||||
guard error == .success else {
|
||||
Logger.fileTransfer.error("Could not delete item with ocId \(identifier.rawValue, privacy: .public) at \(serverFileNameUrl, privacy: OSLogPrivacy.auto(mask: .hash)), received error: \(error.errorDescription, privacy: .public)")
|
||||
completionHandler(error.toFileProviderError())
|
||||
completionHandler(error.fileProviderError)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче