-
Notifications
You must be signed in to change notification settings - Fork 1
/
PresentableError+FromError.swift
44 lines (38 loc) · 1.83 KB
/
PresentableError+FromError.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import FingerprintPro
extension PresentableError {
init(from error: Error) {
switch error {
case FPJSError.networkError:
self = .networkError
case let FPJSError.apiError(underlyingError) where underlyingError.isTokenExpiredError:
self = .publicApiKeyExpiredError
case let FPJSError.apiError(underlyingError) where underlyingError.isTokenNotFoundError:
self = .publicApiKeyInvalidError
case let FPJSError.apiError(underlyingError) where underlyingError.isSubscriptionNotActiveError:
self = .subscriptionNotActiveError
case let FPJSError.apiError(underlyingError) where underlyingError.isTooManyRequestsError:
self = .tooManyRequestsError
case let FPJSError.apiError(underlyingError) where underlyingError.isWrongRegionError:
self = .wrongRegionError
case let error as FingerprintServerAPI.ResponseError where error.isTokenMismatchError:
self = .secretApiKeyMismatchError
case let error as FingerprintServerAPI.ResponseError where error.isTokenNotFoundError:
self = .secretApiKeyInvalidError
default:
self = .unknownError
}
}
}
private extension APIError {
var isTokenExpiredError: Bool { error?.code == .tokenExpired }
var isTokenNotFoundError: Bool { error?.code == .tokenNotFound }
var isSubscriptionNotActiveError: Bool { error?.code == .subscriptionNotActive }
var isTooManyRequestsError: Bool { error?.code == .tooManyRequests }
var isWrongRegionError: Bool { error?.code == .wrongRegion }
}
private extension FingerprintServerAPI.ResponseError {
var isTokenNotFoundError: Bool { code == .tokenNotFound }
var isTokenMismatchError: Bool {
code == .requestNotFound || code == .subscriptionNotActive || code == .wrongRegion
}
}