mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 14:36:01 +03:00
Make NKError extension conversion more legible
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
109258f3ce
commit
a0c819fdbe
1 changed files with 39 additions and 6 deletions
|
@ -17,17 +17,50 @@ import FileProvider
|
||||||
import NextcloudKit
|
import NextcloudKit
|
||||||
|
|
||||||
extension NKError {
|
extension NKError {
|
||||||
func toFileProviderError() -> NSFileProviderError {
|
var isCouldntConnectError: Bool {
|
||||||
|
get {
|
||||||
let nkErrorCode = self.errorCode
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if nkErrorCode == 404 {
|
var isUnauthenticatedError: Bool {
|
||||||
|
get {
|
||||||
|
return self.errorCode == -1013
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var isGoingOverQuotaError: Bool {
|
||||||
|
get {
|
||||||
|
return self.errorCode == 507
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var isNotFoundError: Bool {
|
||||||
|
get {
|
||||||
|
return self.errorCode == 404
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toFileProviderError() -> NSFileProviderError {
|
||||||
|
if self.isNotFoundError {
|
||||||
return NSFileProviderError(.noSuchItem)
|
return NSFileProviderError(.noSuchItem)
|
||||||
} else if nkErrorCode == -9999 || nkErrorCode == -1001 || nkErrorCode == -1004 || nkErrorCode == -1005 || nkErrorCode == -1009 || nkErrorCode == -1012 || nkErrorCode == -1200 || nkErrorCode == -1202 || nkErrorCode == 500 || nkErrorCode == 503 || nkErrorCode == 200 {
|
} else if self.isCouldntConnectError {
|
||||||
// Provide something the file provider can do something with
|
// Provide something the file provider can do something with
|
||||||
return NSFileProviderError(.serverUnreachable)
|
return NSFileProviderError(.serverUnreachable)
|
||||||
} else if nkErrorCode == -1013 {
|
} else if self.isUnauthenticatedError {
|
||||||
return NSFileProviderError(.notAuthenticated)
|
return NSFileProviderError(.notAuthenticated)
|
||||||
} else if nkErrorCode == 507 {
|
} else if self.isGoingOverQuotaError {
|
||||||
return NSFileProviderError(.insufficientQuota)
|
return NSFileProviderError(.insufficientQuota)
|
||||||
} else {
|
} else {
|
||||||
return NSFileProviderError(.cannotSynchronize)
|
return NSFileProviderError(.cannotSynchronize)
|
||||||
|
|
Loading…
Reference in a new issue