#[non_exhaustive]pub enum Error {
Show 62 variants
BadRequest,
InvalidFieldFormat(String),
InvalidMandatoryField(String),
Unauthorized(String),
InvalidTokenB2B,
InvalidCustomerToken,
TokenNotFoundB2B,
CustomerTokenNotFound,
TransactionExpired,
FeatureNotAllowed(String),
ExceedsTransactionAmountLimit,
SuspectedFraud,
ActivityCountLimitExceeded,
DoNotHonor,
FeatureNotAllowedAtThisTime(String),
CardBlocked,
CardExpired,
DormantAccount,
NeedToSetTokenLimit,
OTPBlocked,
OTPLifetimeExpired,
OTPSentToCardholder,
InsufficientFunds,
TransactionNotPermitted(String),
SuspendTransaction,
TokenLimitExceeded,
InactiveCardOrAccountOrCustomer,
MerchantBlacklisted,
MerchantLimitExceed,
SetLimitNotAllowed,
TokenLimitInvalid,
AccountLimitExceed,
InvalidTransactionStatus,
TransactionNotFound,
InvalidRouting,
BankNotSupportedBySwitch,
TransactionCancelled,
MerchantNotRegisteredForCardRegistrationServices,
NeedToRequestOTP,
JourneyNotFound,
InvalidMerchant,
NoIssuer,
InvalidAPITransition,
InvalidCardOrAccountOrCustomerOrVirtualAccount(String),
InvalidBillOrVirtualAccountWithReason(String),
InvalidAmount,
PaidBill,
InvalidOTP,
PartnerNotFound,
InvalidTerminal,
InconsistentRequest,
InvalidBillOrVirtualAccount,
RequestedFunctionIsNotSupported,
RequestedOperationIsNotAllowed,
Conflict,
DuplicatePartnerReferenceNo,
TooManyRequests,
GeneralError,
InternalServerError,
ExternalServerError,
Timeout,
Crypto(Error),
}Expand description
All known SNAP BI error variants plus a feature-gated Crypto bridge.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
BadRequest
General request failed error, including message parsing failed.
InvalidFieldFormat(String)
Invalid format
InvalidMandatoryField(String)
Missing or invalid format on mandatory field
General unauthorized error (No Interface Def, API is Invalid, Oauth Failed, Verify Client Secret Fail, Client Forbidden Access API, Unknown Client, Key not Found).
InvalidTokenB2B
Token found in request is invalid (Access Token Not Exist, Access Token Expiry)
InvalidCustomerToken
Token found in request is invalid (Access Token Not Exist, Access Token Expiry)
TokenNotFoundB2B
Token not found in the system. This occurs on any API that requires token as input parameter
CustomerTokenNotFound
Token not found in the system. This occurs on any API that requires token as input parameter
TransactionExpired
Transaction expired
FeatureNotAllowed(String)
This merchant is not allowed to call Direct Debit APIs
ExceedsTransactionAmountLimit
Exceeds Transaction Amount Limit
SuspectedFraud
Suspected Fraud
ActivityCountLimitExceeded
Too many requests, exceeds transaction frequency limit
DoNotHonor
Account or User status is abnormal
FeatureNotAllowedAtThisTime(String)
Cut off in progress
CardBlocked
The payment card is blocked
CardExpired
The payment card is expired
DormantAccount
The account is dormant
NeedToSetTokenLimit
Need to set token limit
OTPBlocked
OTP has been blocked
OTPLifetimeExpired
OTP has been expired
OTPSentToCardholder
Initiates request OTP to the issuer
InsufficientFunds
Insufficient funds
TransactionNotPermitted(String)
Transaction not permitted
SuspendTransaction
Suspend transaction
TokenLimitExceeded
Purchase amount exceeds the token limit set prior
InactiveCardOrAccountOrCustomer
Inactive account
MerchantBlacklisted
Merchant is suspended from calling any APIs
MerchantLimitExceed
Merchant aggregated purchase amount on that day exceeds the agreed limit
SetLimitNotAllowed
Set limit not allowed on particular token
TokenLimitInvalid
The token limit desired by the merchant is not within the agreed range between the merchant and the Issuer
AccountLimitExceed
Account aggregated purchase amount on that day exceeds the agreed limit
InvalidTransactionStatus
Invalid transaction status
TransactionNotFound
Transaction not found
InvalidRouting
Invalid routing
BankNotSupportedBySwitch
Bank not supported by switch
TransactionCancelled
Transaction is cancelled by customer
MerchantNotRegisteredForCardRegistrationServices
Merchant is not registered for Card Registration services
NeedToRequestOTP
Need to request OTP
JourneyNotFound
The journeyId cannot be found in the system
InvalidMerchant
Merchant does not exist or status abnormal
NoIssuer
No issuer
InvalidAPITransition
Invalid API transition within a journey
InvalidCardOrAccountOrCustomerOrVirtualAccount(String)
Card information may be invalid, or the card account may be blacklisted, or Virtual Account number maybe invalid.
InvalidBillOrVirtualAccountWithReason(String)
The bill or Virtual account is blocked/ suspended/not found.
InvalidAmount
The amount doesn’t match with what supposed to
PaidBill
The bill has been paid
InvalidOTP
OTP is incorrect
PartnerNotFound
Partner number can’t be found
InvalidTerminal
Terminal does not exist in the system
InconsistentRequest
Inconsistent request parameter found for the same partner reference number/transaction id.
InvalidBillOrVirtualAccount
The bill is expired.
RequestedFunctionIsNotSupported
Requested function is not supported
RequestedOperationIsNotAllowed
Requested operation to cancel/refund transaction is not allowed at this time.
Conflict
Cannot use same X-EXTERNAL-ID in same day
DuplicatePartnerReferenceNo
Transaction has previously been processed indicates the same partnerReferenceNo already success
TooManyRequests
Maximum transaction limit exceeded
GeneralError
General Error
InternalServerError
Unknown internal server failure, please retry the process again
ExternalServerError
Backend system failure, etc.
Timeout
Timeout from the issuer
Crypto(Error)
Bridge variant carrying a kamu_snap_crypto::Error. Only present
when the crypto feature is enabled.
Implementations§
Source§impl Error
impl Error
Sourcepub fn category(&self) -> Category
pub fn category(&self) -> Category
Coarse Category for retry-policy / logging consumers.
Examples found in repository?
23fn main() -> Result<(), Box<dyn std::error::Error>> {
24 let wires = [
25 r#"{"responseCode":"2001100","responseMessage":"Successful","accountNo":"1234","currentBalance":"99000.00"}"#,
26 r#"{"responseCode":"4011100","responseMessage":"Unauthorized. Invalid token"}"#,
27 r#"{"responseCode":"4031114","responseMessage":"Insufficient Funds"}"#,
28 // BRI's 6-digit source-doc defect — still parseable, raw preserved.
29 r#"{"responseCode":"500000","responseMessage":"General Error"}"#,
30 ];
31
32 for wire in wires {
33 println!("---");
34 println!("wire: {wire}");
35
36 let resp: SnapResponse<BalancePayload> = serde_json::from_str(wire)?;
37 println!("raw responseCode: {}", resp.envelope.response_code.raw());
38
39 match resp.envelope.response_code.classify() {
40 Some(err) => {
41 println!("classified error: {err}");
42 println!("category: {}", err.category());
43 let action = match err.category() {
44 Category::Business => "do NOT retry (business rule violation)",
45 Category::System => "retry with backoff",
46 Category::Message => "fix client request before retry",
47 Category::Success => "no action",
48 _ => "review manually",
49 };
50 println!("policy: {action}");
51 }
52 None => {
53 if let Some(payload) = resp.payload() {
54 println!("success! account {} balance {}", payload.account_no, payload.current_balance);
55 } else {
56 println!("unrecognized code with no payload — log and escalate");
57 }
58 }
59 }
60 }
61 Ok(())
62}Sourcepub fn http_status(&self) -> StatusCode
pub fn http_status(&self) -> StatusCode
HTTP status code mapped per the SNAP BI taxonomy.
Sourcepub fn response_code(&self, service: ServiceCode) -> ResponseCode
pub fn response_code(&self, service: ServiceCode) -> ResponseCode
Compose the full wire responseCode for this variant under service.
Sourcepub fn from_http_and_case(http: u16, case: u8) -> Option<Self>
pub fn from_http_and_case(http: u16, case: u8) -> Option<Self>
Inverse classifier — given a received (http, case), return the
matching variant with empty payload for string-bearing variants.
None for unknown pairs.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()