Skip to content

Commit 93de01f

Browse files
authored
Fix Cancel Action on Error (#272)
* move operation canceled callback inside the cancel action * return api error if it exists when cancelling. * disable offline mode on enhance selfie capture for now.
1 parent db4d026 commit 93de01f

File tree

2 files changed

+14
-82
lines changed

2 files changed

+14
-82
lines changed

Sources/SmileID/Classes/SelfieCapture/EnhancedSmartSelfieViewModel.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ extension EnhancedSmartSelfieViewModel {
368368

369369
private func handleCancelSelfieCapture() {
370370
invalidateSubmissionTask()
371-
onFinished(callback: onResult)
371+
if let error {
372+
onResult.didError(error: error)
373+
} else {
374+
onResult.didError(error: SmileIDError.operationCanceled("User cancelled"))
375+
}
372376
}
373377
}
374378

@@ -523,8 +527,6 @@ extension EnhancedSmartSelfieViewModel: SelfieSubmissionDelegate {
523527
)
524528
} else if let error = error {
525529
callback.didError(error: error)
526-
} else {
527-
callback.didError(error: SmileIDError.operationCanceled("User cancelled"))
528530
}
529531
}
530532

Sources/SmileID/Classes/SelfieCapture/SelfieSubmissionManager.swift

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ final class SelfieSubmissionManager {
5555
// Create an authentication request based on the job type
5656
let authRequest = createAuthRequest(jobType: jobType)
5757

58-
// Save the job locally if offline mode is allowed
59-
if SmileID.allowOfflineMode {
60-
try saveOfflineMode(jobType: jobType)
61-
}
62-
6358
// Authenticate the request with the API
6459
let authResponse = try await SmileID.api.authenticate(request: authRequest)
6560

@@ -74,9 +69,6 @@ final class SelfieSubmissionManager {
7469
failureReason: failureReason
7570
)
7671

77-
// Update local storage after successful submission
78-
try updateLocalStorageAfterSuccess()
79-
8072
// Send out api response after successful submission
8173
self.delegate?.submissionDidSucceed(response)
8274
} catch let error as SmileIDError {
@@ -103,19 +95,6 @@ final class SelfieSubmissionManager {
10395
)
10496
}
10597

106-
// we need to discuss this
107-
private func saveOfflineMode(jobType: JobType) throws {
108-
try LocalStorage.saveOfflineJob(
109-
jobId: userId,
110-
userId: userId,
111-
jobType: jobType,
112-
enrollment: isEnroll,
113-
allowNewEnroll: allowNewEnroll,
114-
localMetadata: localMetadata,
115-
partnerParams: extraPartnerParams
116-
)
117-
}
118-
11998
private func prepareImagesForSubmission() throws -> (MultipartBody, [MultipartBody]) {
12099
guard let smartSelfieImage = createMultipartBody(from: selfieImageUrl) else {
121100
throw SmileIDError.fileNotFound("Could not create multipart body for file")
@@ -182,64 +161,15 @@ final class SelfieSubmissionManager {
182161
}
183162
}
184163

185-
private func updateLocalStorageAfterSuccess() throws {
186-
// Move the job to the submitted jobs directory for record-keeping
187-
try LocalStorage.moveToSubmittedJobs(jobId: self.userId)
188-
189-
// Update the references to the submitted selfie and liveness images
190-
self.selfieImageUrl = try LocalStorage.getFileByType(
191-
jobId: userId,
192-
fileType: FileType.selfie,
193-
submitted: true
194-
)
195-
self.livenessImages =
196-
try LocalStorage.getFilesByType(
197-
jobId: userId,
198-
fileType: FileType.liveness,
199-
submitted: true
200-
) ?? []
201-
}
202-
203164
private func handleJobSubmissionFailure(_ smileIDError: SmileIDError) {
204-
do {
205-
let didMove = try LocalStorage.handleOfflineJobFailure(jobId: self.userId, error: smileIDError)
206-
if didMove {
207-
self.selfieImageUrl = try LocalStorage.getFileByType(jobId: userId, fileType: .selfie, submitted: true)
208-
self.livenessImages =
209-
try LocalStorage.getFilesByType(jobId: userId, fileType: .liveness, submitted: true) ?? []
210-
}
211-
} catch {
212-
let (errorMessageRes, errorMessage) = toErrorMessage(error: smileIDError)
213-
self.delegate?
214-
.submissionDidFail(
215-
with: error,
216-
errorMessage: errorMessageRes,
217-
errorMessageRes: errorMessage,
218-
updatedSelfieImageUrl: selfieImageUrl,
219-
updatedLivenessImages: livenessImages
220-
)
221-
return
222-
}
223-
224-
if SmileID.allowOfflineMode, SmileIDError.isNetworkFailure(error: smileIDError) {
225-
self.delegate?
226-
.submissionDidFail(
227-
with: smileIDError,
228-
errorMessage: nil,
229-
errorMessageRes: "Offline.Message",
230-
updatedSelfieImageUrl: selfieImageUrl,
231-
updatedLivenessImages: livenessImages
232-
)
233-
} else {
234-
let (errorMessageRes, errorMessage) = toErrorMessage(error: smileIDError)
235-
self.delegate?
236-
.submissionDidFail(
237-
with: smileIDError,
238-
errorMessage: errorMessage,
239-
errorMessageRes: errorMessageRes,
240-
updatedSelfieImageUrl: selfieImageUrl,
241-
updatedLivenessImages: livenessImages
242-
)
243-
}
165+
let (errorMessageRes, errorMessage) = toErrorMessage(error: smileIDError)
166+
self.delegate?
167+
.submissionDidFail(
168+
with: smileIDError,
169+
errorMessage: errorMessage,
170+
errorMessageRes: errorMessageRes,
171+
updatedSelfieImageUrl: selfieImageUrl,
172+
updatedLivenessImages: livenessImages
173+
)
244174
}
245175
}

0 commit comments

Comments
 (0)