Skip to content

Commit 6801a15

Browse files
author
Ruben Nine
committed
Moving Defaults.maxRetries inside the relevant operation.
Improving error message.
1 parent 0197419 commit 6801a15

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

FilestackSDK/Internal/Operations/CommitPartUploadOperation.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ class CommitPartUploadOperation: BaseOperation<HTTPURLResponse> {
1414

1515
private let descriptor: UploadDescriptor
1616
private let part: Int
17-
private let retries: Int
1817
private var retrier: TaskRetrier<HTTPURLResponse>?
1918

2019
// MARK: - Lifecyle
2120

22-
required init(descriptor: UploadDescriptor, part: Int, retries: Int) {
21+
required init(descriptor: UploadDescriptor, part: Int) {
2322
self.descriptor = descriptor
2423
self.part = part
25-
self.retries = retries
2624

2725
super.init()
2826
}
@@ -56,7 +54,7 @@ private extension CommitPartUploadOperation {
5654
func upload() {
5755
let uploadURL = URL(string: "multipart/commit", relativeTo: Constants.uploadURL)!
5856

59-
retrier = .init(attempts: retries, label: uploadURL.relativePath) { (semaphore) -> HTTPURLResponse? in
57+
retrier = .init(attempts: Defaults.maxRetries, label: uploadURL.relativePath) { (semaphore) -> HTTPURLResponse? in
6058
var httpURLResponse: HTTPURLResponse?
6159

6260
UploadService.shared.upload(multipartFormData: self.multipartFormData, url: uploadURL) { response in
@@ -88,3 +86,11 @@ private extension CommitPartUploadOperation {
8886
form.append(descriptor.options.storeOptions.location.description, named: "store_location")
8987
}
9088
}
89+
90+
// MARK: - Defaults
91+
92+
private extension CommitPartUploadOperation {
93+
struct Defaults {
94+
static let maxRetries = 5
95+
}
96+
}

FilestackSDK/Internal/Operations/CompleteUploadOperation.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ class CompleteUploadOperation: BaseOperation<JSONResponse> {
1414

1515
private let partsAndEtags: [Int: String]
1616
private let descriptor: UploadDescriptor
17-
private let retries: Int
1817
private var retrier: TaskRetrier<JSONResponse>?
1918

2019
// MARK: - Lifecycle
2120

22-
required init(partsAndEtags: [Int: String], retries: Int, descriptor: UploadDescriptor) {
21+
required init(partsAndEtags: [Int: String], descriptor: UploadDescriptor) {
2322
self.partsAndEtags = partsAndEtags
24-
self.retries = retries
2523
self.descriptor = descriptor
2624

2725
super.init()
@@ -56,7 +54,7 @@ private extension CompleteUploadOperation {
5654
func upload() {
5755
let uploadURL = URL(string: "multipart/complete", relativeTo: Constants.uploadURL)!
5856

59-
retrier = .init(attempts: retries, label: uploadURL.relativePath) { (semaphore) -> JSONResponse? in
57+
retrier = .init(attempts: Defaults.maxRetries, label: uploadURL.relativePath) { (semaphore) -> JSONResponse? in
6058
var jsonResponse: JSONResponse?
6159

6260
UploadService.shared.upload(multipartFormData: self.multipartFormData, url: uploadURL) { response in
@@ -102,3 +100,11 @@ private extension CompleteUploadOperation {
102100
}
103101
}
104102
}
103+
104+
// MARK: - Defaults
105+
106+
private extension CompleteUploadOperation {
107+
struct Defaults {
108+
static let maxRetries = 5
109+
}
110+
}

FilestackSDK/Internal/Operations/SubmitPartIntelligentUploadOperation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private extension SubmitPartIntelligentUploadOperation {
8282
guard !isCancelled else { return nil }
8383

8484
guard retries > 0 else {
85-
finish(with: .failure(.custom("Too many retries.")))
85+
finish(with: .failure(.custom("Exceeded max retries trying to submit data chunk.")))
8686
return nil
8787
}
8888

@@ -133,7 +133,7 @@ private extension SubmitPartIntelligentUploadOperation {
133133
func executeCommit() {
134134
guard !isCancelled else { return }
135135

136-
let commitOperation = CommitPartUploadOperation(descriptor: descriptor, part: number, retries: Defaults.maxRetries)
136+
let commitOperation = CommitPartUploadOperation(descriptor: descriptor, part: number)
137137

138138
commitOperation.completionBlock = {
139139
switch commitOperation.result {
@@ -155,6 +155,6 @@ private extension SubmitPartIntelligentUploadOperation {
155155
static let resumableMobileChunkSize = 1_048_576
156156
static let resumableDesktopChunkSize = 8_388_608
157157
static let minimumPartChunkSize = 32_768
158-
static let maxRetries: Int = 5
158+
static let maxRetries = 5
159159
}
160160
}

FilestackSDK/Internal/Operations/UploadOperation.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,10 @@ private extension UploadOperation {
178178
completion: @escaping (CompleteUploadOperation.Result) -> Void) {
179179
guard !isCancelled else { return }
180180

181-
let completeOperation = CompleteUploadOperation(partsAndEtags: partsAndEtags,
182-
retries: Defaults.maxRetries,
183-
descriptor: descriptor)
181+
let completeOperation = CompleteUploadOperation(partsAndEtags: partsAndEtags, descriptor: descriptor)
184182

185183
completeOperation.completionBlock = { completion(completeOperation.result) }
186184

187185
operationQueue.addOperation(completeOperation)
188186
}
189187
}
190-
191-
// MARK: - Defaults
192-
193-
private extension UploadOperation {
194-
struct Defaults {
195-
static let maxRetries = 5
196-
}
197-
}

0 commit comments

Comments
 (0)