Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FirebaseStorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 11.0.0
- [fixed] Updated error handling to support both Swift error enum handling and NSError error
handling. Some of the Swift enums have additional parameters which may be a **breaking** change.
There are additional NSError's for completeness, but nothing related to NSError handling is
breaking. (#13071, #10889, #13114)

# 10.24.0
- [fixed] `putFile` and `putFileAsync` now work in app extensions. A background session
configuration is not used when uploading from an app extension (#12579).
Expand Down
9 changes: 6 additions & 3 deletions FirebaseStorage/Sources/AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public extension StorageReference {
}
uploadTask.observe(.failure) { snapshot in
continuation.resume(with: .failure(
snapshot.error ?? StorageError.internalError("Internal Storage Error in putDataAsync")
snapshot.error ?? StorageError
.internalError(message: "Internal Storage Error in putDataAsync")
))
}
}
Expand Down Expand Up @@ -103,7 +104,8 @@ public extension StorageReference {
}
uploadTask.observe(.failure) { snapshot in
continuation.resume(with: .failure(
snapshot.error ?? StorageError.internalError("Internal Storage Error in putFileAsync")
snapshot.error ?? StorageError
.internalError(message: "Internal Storage Error in putFileAsync")
))
}
}
Expand Down Expand Up @@ -137,7 +139,8 @@ public extension StorageReference {
}
downloadTask.observe(.failure) { snapshot in
continuation.resume(with: .failure(
snapshot.error ?? StorageError.internalError("Internal Storage Error in writeAsync")
snapshot.error ?? StorageError
.internalError(message: "Internal Storage Error in writeAsync")
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class StorageGetDownloadURLTask: StorageTask, StorageTaskManagement {
.jsonObject(with: data) as? [String: Any] {
downloadURL = self.downloadURLFromMetadataDictionary(responseDictionary)
if downloadURL == nil {
self.error = NSError(domain: StorageErrorDomain,
code: StorageErrorCode.unknown.rawValue,
userInfo: [NSLocalizedDescriptionKey:
"Failed to retrieve a download URL."])
self.error = StorageError.unknown(
message: "Failed to retrieve a download URL.",
serverError: [:]
) as NSError
}
} else {
self.error = StorageErrorCode.error(withInvalidRequest: data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ class StorageTokenAuthorizer: NSObject, GTMSessionFetcherAuthorizer {
var errorDictionary = error.userInfo
errorDictionary["ResponseErrorDomain"] = error.domain
errorDictionary["ResponseErrorCode"] = error.code
errorDictionary[NSLocalizedDescriptionKey] =
"User is not authenticated, please authenticate" +
" using Firebase Authentication and try again."
tokenError = NSError(domain: "FIRStorageErrorDomain",
code: StorageErrorCode.unauthenticated.rawValue,
userInfo: errorDictionary)
tokenError = StorageError.unauthenticated(serverError: errorDictionary) as NSError
} else if let token {
let firebaseToken = "Firebase \(token)"
request?.setValue(firebaseToken, forHTTPHeaderField: "Authorization")
Expand Down
6 changes: 4 additions & 2 deletions FirebaseStorage/Sources/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ private func getResultCallback<T>(completion: @escaping (Result<T, Error>) -> Vo
if let value {
completion(.success(value))
} else if let error {
completion(.failure(StorageError.swiftConvert(objcError: error as NSError)))
completion(.failure(error))
} else {
completion(.failure(StorageError.internalError("Internal failure in getResultCallback")))
completion(.failure(StorageError.internalError(
message: "Internal failure in getResultCallback"
)))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions FirebaseStorage/Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ import FirebaseCore
do {
path = try StoragePath.path(string: url.absoluteString)
} catch let StoragePathError.storagePathError(message) {
throw StorageError.pathError(message)
throw StorageError.pathError(message: message)
} catch {
throw StorageError.pathError("Internal error finding StoragePath: \(error)")
throw StorageError.pathError(message: "Internal error finding StoragePath: \(error)")
}

// If no default bucket exists (empty string), accept anything.
Expand All @@ -205,7 +205,7 @@ import FirebaseCore
// If there exists a default bucket, throw if provided a different bucket.
if path.bucket != storageBucket {
throw StorageError
.bucketMismatch("Provided bucket: `\(path.bucket)` does not match the Storage " +
.bucketMismatch(message: "Provided bucket: `\(path.bucket)` does not match the Storage " +
"bucket of the current instance: `\(storageBucket)`")
}
return StorageReference(storage: self, path: path)
Expand Down
3 changes: 1 addition & 2 deletions FirebaseStorage/Sources/StorageDownloadTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ open class StorageDownloadTask: StorageObservableTask, StorageTaskManagement {
* Cancels a task.
*/
@objc open func cancel() {
let error = StorageErrorCode.error(withCode: .cancelled)
cancel(withError: error)
cancel(withError: StorageError.cancelled as NSError)
}

/**
Expand Down
Loading