Skip to main content

Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

BadRequest

General request failed error, including message parsing failed.

§

InvalidFieldFormat(String)

Invalid format

§

InvalidMandatoryField(String)

Missing or invalid format on mandatory field

§

Unauthorized(String)

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

Source

pub fn category(&self) -> Category

Coarse Category for retry-policy / logging consumers.

Examples found in repository?
examples/client_parse.rs (line 42)
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}
Source

pub fn http_status(&self) -> StatusCode

HTTP status code mapped per the SNAP BI taxonomy.

Source

pub fn case_code(&self) -> u8

2-digit case code embedded in the responseCode.

Source

pub fn response_code(&self, service: ServiceCode) -> ResponseCode

Compose the full wire responseCode for this variant under service.

Source

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 Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V