Skip to main content

TrustFactor Errors

All errors produced by the TrustFactor SDK are wrapped in TrustFactorError. Match on the domain property to identify the error category and specific code.

info

Swift: Error domains are enums making it easier to spot differences if any of them change. If switching, the compiler will force you to handle all the cases.

TrustFactorError

The top-level SDK error type.

public struct TrustFactorError: Error {
public enum Domain: Hashable {
case client(code: ClientDomainCode)
case authentication(code: AuthenticationDomainCode)
case network(code: NetworkDomainCode)
case operationDecision(code: OperationDecisionDomainCode)
case profileAction(code: ProfileActionDomainCode)
case unknown
}

public let domain: Domain
public let parameters: [String: Any]

public init(domain: Domain, parameters: [String: Any] = [:])
}

Example of usage

let error: TrustFactorError = ....

switch error.domain {
case .client(code: let code):
handleClientError(code)

case .authentication(code: let code):
// handle

case .network(code: let code):
// handle

case .operationDecision(code: let code):
// handle

case .profileAction(code: let code):
// handle

case .unknown:
break
}

func handleClientError(_ code: TrustFactorError.ClientDomainCode) {
switch code {
case .notStarted:
// call TrustFactor.getClient(....)

case .deviceNotRegistered:
// call trustfactorClient.register(...)

// ...
}
}