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.
- iOS (Swift)
- Android (Java)
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] = [:])
}
// Named Error on Android
public class Error extends Exception {
public Error(Domain domain, Enum<?> domainCode, HashMap<String, String> parameters)
public Domain getDomain()
public Enum<?> getDomainCode()
public HashMap<String, String> getParameters()
}
Example of usage
- iOS (Swift)
- Android (Java)
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(...)
// ...
}
}
switch (error.getDomain()) {
case CLIENT:
handleClientError(error.getDomainCode());
break;
case AUTHENTICATION:
// handle
break;
case NETWORK:
// handle
break;
case OPERATION_DECISION:
// handle
break;
case PROFILE_ACTION:
// handle
break;
case UNKNOWN:
// handle
break;
}
void handleClientError(Enum<?> domainCode) {
if (domainCode instanceof ClientDomainCode code) {
switch (code) {
case NOT_STARTED -> {
// call TrustFactor.getClient(....)
}
case DEVICE_NOT_REGISTERED -> {
// call trustfactorClient.register(...)
}
// ...
}
}
}