Skip to content
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

chore: handle decoding errors #152

Closed
Closed
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
2 changes: 2 additions & 0 deletions HostApp/HostApp/Views/ExampleLivenessView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct ExampleLivenessView: View {
viewModel.presentationState = .error(.countdownFaceTooClose)
case .failure(.invalidSignature):
viewModel.presentationState = .error(.invalidSignature)
case .failure(.runtimeError):
viewModel.presentationState = .error(.runtimeError)
default:
viewModel.presentationState = .liveness
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public struct FaceLivenessDetectionError: Error, Equatable {
message: "The signature on the request is invalid.",
recoverySuggestion: "Ensure the device time is correct and try again."
)

public static let runtimeError = FaceLivenessDetectionError(
code: 18,
message: "An unexpected runtime error occurred.",
recoverySuggestion: "Please try again."
)

public static func == (lhs: FaceLivenessDetectionError, rhs: FaceLivenessDetectionError) -> Bool {
lhs.code == rhs.code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public struct FaceLivenessDetectorView: View {
isPreviewScreenEnabled: !disableStartView
)
)

faceDetector.setFaceDetectionSessionConfigurationWrapper(configuration: viewModel)
}

init(
Expand Down Expand Up @@ -143,6 +141,22 @@ public struct FaceLivenessDetectorView: View {
throw FaceLivenessDetectionError.accessDenied
}
}
DispatchQueue.main.async {
if let faceDetector = viewModel.faceDetector as? FaceDetectorShortRange.Model {
faceDetector.setFaceDetectionSessionConfigurationWrapper(configuration: viewModel)
}
}
}
.onReceive(viewModel.$livenessState) { output in
switch output.state {
case .encounteredUnrecoverableError(let error):
let closeCode = error.webSocketCloseCode ?? .normalClosure
viewModel.livenessService?.closeSocket(with: closeCode)
isPresented = false
onCompletion(.failure(mapError(error)))
default:
break
}
}
case .awaitingLivenessSession(let challenge):
Color.clear
Expand All @@ -157,7 +171,6 @@ public struct FaceLivenessDetectorView: View {
}
}
}

case .displayingGetReadyView(let challenge):
GetReadyPageView(
onBegin: {
Expand Down Expand Up @@ -219,6 +232,8 @@ public struct FaceLivenessDetectorView: View {
return .faceInOvalMatchExceededTimeLimitError
case .socketClosed:
return .socketClosed
case .runtimeError:
return .runtimeError
default:
return .cameraPermissionDenied
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class FaceLivenessDetectionViewModel: ObservableObject {
self?.livenessState
.unrecoverableStateEncountered(.socketClosed)
}
case .runtimeError:
DispatchQueue.main.async {
self?.livenessState
.unrecoverableStateEncountered(.runtimeError)
}
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct LivenessStateMachine {
static let timedOut = LivenessError(code: 4, webSocketCloseCode: .ovalFitMatchTimeout)
static let couldNotOpenStream = LivenessError(code: 5, webSocketCloseCode: .unexpectedRuntimeError)
static let socketClosed = LivenessError(code: 6, webSocketCloseCode: .normalClosure)
static let runtimeError = LivenessError(code: 7, webSocketCloseCode: .unexpectedRuntimeError)
static let viewResignation = LivenessError(code: 8, webSocketCloseCode: .viewClosure)

static func == (lhs: LivenessError, rhs: LivenessError) -> Bool {
Expand Down
Loading