Skip to main content

TrustFactor Errors

To make it easier to understand the causes of an error we made a specific error type with domain and parameters.

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.

Error definition

struct Error: Error {
public let domain: Domain
public let parameters: [String: Any]
}

Domains

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

Example of usage

Error definition

let error: Error = ....

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: Error.ClientDomainCode) {
switch code {
case .notStarted:
// call TrustFactor.getClient(....)

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