-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[swift5] Remove optional from body #10938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -160,100 +160,20 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>() | |||||
| let validatedRequest = request.validate() | ||||||
|
|
||||||
| switch T.self { | ||||||
| case is String.Type: | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When response type is void, getNonDecodableBuilder is used
|
||||||
| validatedRequest.responseString(queue: apiResponseQueue, completionHandler: { stringResponse in | ||||||
| cleanupRequest() | ||||||
|
|
||||||
| switch stringResponse.result { | ||||||
| case let .success(value): | ||||||
| completion(.success(Response(response: stringResponse.response!, body: value as? T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.response, error))) | ||||||
| } | ||||||
|
|
||||||
| }) | ||||||
| case is URL.Type: | ||||||
| validatedRequest.responseData(queue: apiResponseQueue, completionHandler: { dataResponse in | ||||||
| cleanupRequest() | ||||||
|
|
||||||
| do { | ||||||
|
|
||||||
| guard case .success = dataResponse.result else { | ||||||
| throw DownloadException.responseFailed | ||||||
| } | ||||||
|
|
||||||
| guard let data = dataResponse.data else { | ||||||
| throw DownloadException.responseDataMissing | ||||||
| } | ||||||
|
|
||||||
| guard let request = request.request else { | ||||||
| throw DownloadException.requestMissing | ||||||
| } | ||||||
|
|
||||||
| let fileManager = FileManager.default | ||||||
| let urlRequest = try request.asURLRequest() | ||||||
| let cachesDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] | ||||||
| let requestURL = try self.getURL(from: urlRequest) | ||||||
|
|
||||||
| var requestPath = try self.getPath(from: requestURL) | ||||||
|
|
||||||
| if let headerFileName = self.getFileName(fromContentDisposition: dataResponse.response?.allHeaderFields["Content-Disposition"] as? String) { | ||||||
| requestPath = requestPath.appending("/\(headerFileName)") | ||||||
| } else { | ||||||
| requestPath = requestPath.appending("/tmp.{{projectName}}.\(UUID().uuidString)") | ||||||
| } | ||||||
|
|
||||||
| let filePath = cachesDirectory.appendingPathComponent(requestPath) | ||||||
| let directoryPath = filePath.deletingLastPathComponent().path | ||||||
|
|
||||||
| try fileManager.createDirectory(atPath: directoryPath, withIntermediateDirectories: true, attributes: nil) | ||||||
| try data.write(to: filePath, options: .atomic) | ||||||
|
|
||||||
| completion(.success(Response(response: dataResponse.response!, body: filePath as? T))) | ||||||
|
|
||||||
| } catch let requestParserError as DownloadException { | ||||||
| completion(.failure(ErrorResponse.error(400, dataResponse.data, dataResponse.response, requestParserError))) | ||||||
| } catch { | ||||||
| completion(.failure(ErrorResponse.error(400, dataResponse.data, dataResponse.response, error))) | ||||||
| } | ||||||
| return | ||||||
| }) | ||||||
| case is Void.Type: | ||||||
| validatedRequest.responseData(queue: apiResponseQueue, completionHandler: { voidResponse in | ||||||
| cleanupRequest() | ||||||
|
|
||||||
| switch voidResponse.result { | ||||||
| case .success: | ||||||
| completion(.success(Response(response: voidResponse.response!, body: nil))) | ||||||
| completion(.success(Response(response: voidResponse.response!, body: () as! T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.response, error))) | ||||||
| } | ||||||
|
|
||||||
| }) | ||||||
| case is Data.Type: | ||||||
| validatedRequest.responseData(queue: apiResponseQueue, completionHandler: { dataResponse in | ||||||
| cleanupRequest() | ||||||
|
|
||||||
| switch dataResponse.result { | ||||||
| case .success: | ||||||
| completion(.success(Response(response: dataResponse.response!, body: dataResponse.data as? T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.response, error))) | ||||||
| } | ||||||
|
|
||||||
| }) | ||||||
| default: | ||||||
| validatedRequest.responseData(queue: apiResponseQueue, completionHandler: { dataResponse in | ||||||
| cleanupRequest() | ||||||
|
|
||||||
| switch dataResponse.result { | ||||||
| case .success: | ||||||
| completion(.success(Response(response: dataResponse.response!, body: dataResponse.data as? T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.response, error))) | ||||||
| } | ||||||
|
|
||||||
| }) | ||||||
| fatalError("Unsupported Response Body Type - \(String(describing: T.self))") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -338,7 +258,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>() | |||||
|
|
||||||
| switch stringResponse.result { | ||||||
| case let .success(value): | ||||||
| completion(.success(Response(response: stringResponse.response!, body: value as? T))) | ||||||
| completion(.success(Response(response: stringResponse.response!, body: value as! T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.response, error))) | ||||||
| } | ||||||
|
|
@@ -381,7 +301,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>() | |||||
| try fileManager.createDirectory(atPath: directoryPath, withIntermediateDirectories: true, attributes: nil) | ||||||
| try data.write(to: filePath, options: .atomic) | ||||||
|
|
||||||
| completion(.success(Response(response: dataResponse.response!, body: filePath as? T))) | ||||||
| completion(.success(Response(response: dataResponse.response!, body: filePath as! T))) | ||||||
|
|
||||||
| } catch let requestParserError as DownloadException { | ||||||
| completion(.failure(ErrorResponse.error(400, dataResponse.data, dataResponse.response, requestParserError))) | ||||||
|
|
@@ -396,7 +316,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>() | |||||
|
|
||||||
| switch voidResponse.result { | ||||||
| case .success: | ||||||
| completion(.success(Response(response: voidResponse.response!, body: nil))) | ||||||
| completion(.success(Response(response: voidResponse.response!, body: () as! T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(voidResponse.response?.statusCode ?? 500, voidResponse.data, voidResponse.response, error))) | ||||||
| } | ||||||
|
|
@@ -408,7 +328,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>() | |||||
|
|
||||||
| switch dataResponse.result { | ||||||
| case .success: | ||||||
| completion(.success(Response(response: dataResponse.response!, body: dataResponse.data as? T))) | ||||||
| completion(.success(Response(response: dataResponse.response!, body: dataResponse.data as! T))) | ||||||
| case let .failure(error): | ||||||
| completion(.failure(ErrorResponse.error(dataResponse.response?.statusCode ?? 500, dataResponse.data, dataResponse.response, error))) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@funzin please search and replace all occurrences of
response.body!withresponse.bodyin this class, to fix all the cases. ThanksThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have already checked
response.body!inswift5dbdc585
Maybe, CI will be succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@4brunu
CI ✅