diff --git a/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift b/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift index f492c42..afc5398 100644 --- a/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift +++ b/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift @@ -579,7 +579,7 @@ public class BoxCloudProvider: CloudProvider { private func convertStandardError(_ error: Error) -> Error { switch error { - case let error as BoxAPIError where error.responseInfo.statusCode == 401: + case let error as BoxAPIError where (error.responseInfo.statusCode == 400 && error.responseInfo.rawBody?.contains("invalid_grant") == true) || error.responseInfo.statusCode == 401: return CloudProviderError.unauthorized case let error as BoxAPIError where error.responseInfo.statusCode == 404: return CloudProviderError.itemNotFound diff --git a/Sources/CryptomatorCloudAccess/Dropbox/DropboxCloudProvider.swift b/Sources/CryptomatorCloudAccess/Dropbox/DropboxCloudProvider.swift index c104d4f..cdfd941 100644 --- a/Sources/CryptomatorCloudAccess/Dropbox/DropboxCloudProvider.swift +++ b/Sources/CryptomatorCloudAccess/Dropbox/DropboxCloudProvider.swift @@ -192,7 +192,7 @@ public class DropboxCloudProvider: CloudProvider { } if let networkError = networkError { CloudAccessDDLogDebug("DropboxCloudProvider: fetchItemMetadata(at: \(cloudPath.path)) failed with networkError: \(networkError)") - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) return } guard let result = result else { @@ -241,7 +241,7 @@ public class DropboxCloudProvider: CloudProvider { } if let networkError = networkError { CloudAccessDDLogDebug("DropboxCloudProvider: fetchItemList(at: \(cloudPath.path)) failed with networkError: \(networkError)") - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) return } guard let result = result else { @@ -284,7 +284,7 @@ public class DropboxCloudProvider: CloudProvider { if networkError.isBadInputError(), let errorContent = networkError.errorContent, errorContent.contains("invalidPageToken") { reject(CloudProviderError.pageTokenInvalid) } else { - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) } return } @@ -331,7 +331,7 @@ public class DropboxCloudProvider: CloudProvider { if networkError.isClientError(), case CocoaError.fileWriteFileExists = networkError.asClientError().nsError { reject(CloudProviderError.itemAlreadyExists) } else { - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) } return } @@ -395,13 +395,13 @@ public class DropboxCloudProvider: CloudProvider { guard let requestError = fileUrlsToRequestErrors[localURL] else { return DropboxError.unexpectedError } - return convertRequestErrorToDropboxError(requestError) + return convertRequestError(requestError) } else if let finishBatchRouteError = finishBatchRouteError { CloudAccessDDLogDebug("DropboxCloudProvider: handleBatchUploadMissingResult(for: \(localURL)) failed with finishBatchRouteError: \(finishBatchRouteError)") return DropboxError.asyncPollError } else if let finishBatchRequestError = finishBatchRequestError { CloudAccessDDLogDebug("DropboxCloudProvider: handleBatchUploadMissingResult(for: \(localURL)) failed with finishBatchRequestError: \(finishBatchRequestError)") - return convertRequestErrorToDropboxError(finishBatchRequestError) + return convertRequestError(finishBatchRequestError) } else { CloudAccessDDLogDebug("DropboxCloudProvider: handleBatchUploadMissingResult(for: \(localURL)) failed with missingResult") return DropboxError.missingResult @@ -437,7 +437,7 @@ public class DropboxCloudProvider: CloudProvider { } if let networkError = networkError { CloudAccessDDLogDebug("DropboxCloudProvider: uploadSmallFile(from: \(localURL), to: \(cloudPath.path), mode: \(mode?.description() ?? "nil")) failed with networkError: \(networkError)") - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) return } guard let result = result else { @@ -473,7 +473,7 @@ public class DropboxCloudProvider: CloudProvider { } if let networkError = networkError { CloudAccessDDLogDebug("DropboxCloudProvider: createFolder(at: \(cloudPath.path)) failed with networkError: \(networkError)") - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) return } guard let result = result else { @@ -506,7 +506,7 @@ public class DropboxCloudProvider: CloudProvider { } if let networkError = networkError { CloudAccessDDLogDebug("DropboxCloudProvider: deleteItem(at: \(cloudPath.path)) failed with networkError: \(networkError)") - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) return } guard let result = result else { @@ -545,7 +545,7 @@ public class DropboxCloudProvider: CloudProvider { } if let networkError = networkError { CloudAccessDDLogDebug("DropboxCloudProvider: moveItem(from: \(sourceCloudPath.path), to: \(targetCloudPath.path)) failed with networkError: \(networkError)") - reject(self.convertRequestErrorToDropboxError(networkError)) + reject(self.convertRequestError(networkError)) return } guard let result = result else { @@ -642,26 +642,26 @@ public class DropboxCloudProvider: CloudProvider { } } - func convertRequestErrorToDropboxError(_ error: DBRequestError) -> DropboxError { + func convertRequestError(_ error: DBRequestError) -> Error { if error.isHttpError() { - return .httpError + return DropboxError.httpError } else if error.isBadInputError() { - return .badInputError + return DropboxError.badInputError } else if error.isAuthError() { - return .authError + return CloudProviderError.unauthorized } else if error.isAccessError() { - return .accessError + return DropboxError.accessError } else if error.isPathRootError() { - return .pathRootError + return DropboxError.pathRootError } else if error.isRateLimitError() { let rateLimitError = error.asRateLimitError() - return .rateLimitError(retryAfter: rateLimitError.backoff.intValue) + return DropboxError.rateLimitError(retryAfter: rateLimitError.backoff.intValue) } else if error.isInternalServerError() { - return .internalServerError + return DropboxError.internalServerError } else if error.isClientError() { - return .clientError + return DropboxError.clientError } else { - return .unexpectedError + return DropboxError.unexpectedError } } } diff --git a/Sources/CryptomatorCloudAccess/Dropbox/DropboxError.swift b/Sources/CryptomatorCloudAccess/Dropbox/DropboxError.swift index dfc0004..b515ebe 100644 --- a/Sources/CryptomatorCloudAccess/Dropbox/DropboxError.swift +++ b/Sources/CryptomatorCloudAccess/Dropbox/DropboxError.swift @@ -17,7 +17,6 @@ public enum DropboxError: Error { case httpError case badInputError - case authError case accessError case pathRootError case rateLimitError(retryAfter: Int) diff --git a/Sources/CryptomatorCloudAccess/GoogleDrive/GoogleDriveCloudProvider.swift b/Sources/CryptomatorCloudAccess/GoogleDrive/GoogleDriveCloudProvider.swift index d8f6088..7a11d9f 100644 --- a/Sources/CryptomatorCloudAccess/GoogleDrive/GoogleDriveCloudProvider.swift +++ b/Sources/CryptomatorCloudAccess/GoogleDrive/GoogleDriveCloudProvider.swift @@ -6,6 +6,7 @@ // Copyright © 2020 Skymatic GmbH. All rights reserved. // +import AppAuthCore import Foundation import GoogleAPIClientForREST_Drive import GRDB @@ -532,7 +533,7 @@ public class GoogleDriveCloudProvider: CloudProvider { CloudAccessDDLogDebug("GoogleDriveCloudProvider: executeQuery(\(query.requestID)) failed with error: \(error)") if error.domain == NSURLErrorDomain, error.code == NSURLErrorNotConnectedToInternet || error.code == NSURLErrorCannotConnectToHost || error.code == NSURLErrorNetworkConnectionLost || error.code == NSURLErrorDNSLookupFailed || error.code == NSURLErrorResourceUnavailable || error.code == NSURLErrorInternationalRoamingOff { reject(CloudProviderError.noInternetConnection) - } else if error.domain == kGTLRErrorObjectDomain, error.code == 401 || error.code == 403 { + } else if (error.domain == kGTLRErrorObjectDomain && (error.code == 401 || error.code == 403)) || (error.domain == OIDOAuthTokenErrorDomain && error.code == OIDErrorCodeOAuth.invalidGrant.rawValue) { reject(CloudProviderError.unauthorized) } else if error.domain == kGTLRErrorObjectDomain, error.code == 404 { reject(CloudProviderError.itemNotFound)