-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.oak
More file actions
68 lines (57 loc) · 2.54 KB
/
errors.oak
File metadata and controls
68 lines (57 loc) · 2.54 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// luna-api/errors provides error type constants and error-inspection utilities
// matching the Privy SDK's exported error helpers.
// --- Error Types -------------------------------------------------------------
// PrivyErrorType enumerates all known Privy SDK error type strings.
PrivyErrorType := {
error: 'error'
invalidRequestArguments: 'invalid_request_arguments'
walletNotOnDevice: 'wallet_not_on_device'
invalidRecoveryPin: 'invalid_recovery_pin'
insufficientFunds: 'insufficient_funds'
missingOrInvalidMfa: 'missing_or_invalid_mfa'
mfaVerificationMaxAttempts: 'mfa_verification_max_attempts_reached'
mfaTimeout: 'mfa_timeout'
twilioVerificationFailed: 'twilio_verification_failed'
}
// AllErrorTypes is the ordered list of all known error type strings.
AllErrorTypes := [
'error'
'invalid_request_arguments'
'wallet_not_on_device'
'invalid_recovery_pin'
'insufficient_funds'
'missing_or_invalid_mfa'
'mfa_verification_max_attempts_reached'
'mfa_timeout'
'twilio_verification_failed'
]
// --- Error Validators --------------------------------------------------------
// isPrivyError? checks whether an error object has a valid Privy error type.
fn isPrivyError?(err) if err {
? -> false
_ -> if type(err.type) {
:string -> {
fn go(i) if i {
len(AllErrorTypes) -> false
_ -> if AllErrorTypes.(i) {
err.type -> true
_ -> go(i + 1)
}
}
go(0)
}
_ -> false
}
}
// errorIndicatesMfaTimeout returns true if error type is mfa_timeout.
fn errorIndicatesMfaTimeout(err) isPrivyError?(err) & err.type = 'mfa_timeout'
// errorIndicatesMfaVerificationFailed returns true if error type is missing_or_invalid_mfa.
fn errorIndicatesMfaVerificationFailed(err) isPrivyError?(err) & err.type = 'missing_or_invalid_mfa'
// errorIndicatesMaxMfaRetries returns true if error type is mfa_verification_max_attempts_reached.
fn errorIndicatesMaxMfaRetries(err) isPrivyError?(err) & err.type = 'mfa_verification_max_attempts_reached'
// errorIndicatesWalletNotOnDevice returns true if error type is wallet_not_on_device.
fn errorIndicatesWalletNotOnDevice(err) isPrivyError?(err) & err.type = 'wallet_not_on_device'
// errorIndicatesInvalidRecoveryPin returns true if error type is invalid_recovery_pin or invalid_request_arguments.
fn errorIndicatesInvalidRecoveryPin(err) isPrivyError?(err) & (err.type = 'invalid_recovery_pin' | err.type = 'invalid_request_arguments')
// errorIndicatesInsufficientFunds returns true if error type is insufficient_funds.
fn errorIndicatesInsufficientFunds(err) isPrivyError?(err) & err.type = 'insufficient_funds'