Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error { Config(&'static str), Param(&'static str), Notify { message: String, }, VerifyFailed, Api { endpoint: Endpoint, code: i32, message: String, }, Transport { kind: TransportErrorKind, message: String, }, Http { status: u16, body: String, }, InvalidResponse { endpoint: Endpoint, message: String, }, ResponseTooLarge { limit: usize, }, }
Expand description

EPay SDK error.

Error text generated by the built-in client never includes a request URL. Response previews are bounded and have key / sign values masked.

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.
§

Config(&'static str)

Invalid client or protocol configuration.

§

Param(&'static str)

Invalid outbound request parameter.

§

Notify

A notification was malformed, unauthenticated by metadata, or structurally invalid. Signature mismatches use Error::VerifyFailed.

Fields

§message: String

Redacted description of the rejection.

§

VerifyFailed

MD5 signature verification failed.

§

Api

The gateway answered with a non-success code.

Fields

§endpoint: Endpoint

Endpoint that produced the error.

§code: i32

Gateway code value.

§message: String

Gateway msg value, redacted.

§

Transport

The HTTP transport failed before a response status was available.

Fields

§kind: TransportErrorKind

Failure classification.

§message: String

Redacted, URL-free description.

§

Http

The gateway returned a non-2xx status.

Fields

§status: u16

HTTP status code.

§body: String

Redacted preview of the response body.

§

InvalidResponse

The gateway reported success but the payload is unusable.

Fields

§endpoint: Endpoint

Endpoint that produced the response.

§message: String

Redacted description including a bounded body preview.

§

ResponseTooLarge

The response body exceeded the configured limit.

Fields

§limit: usize

Configured limit in bytes.

Implementations§

Source§

impl Error

Source

pub fn kind(&self) -> ErrorKind

Coarse category; see ErrorKind.

Source

pub fn code(&self) -> i32

Numeric error code, compatible with the original Go SDK mapping.

Source

pub fn endpoint(&self) -> Option<Endpoint>

Gateway endpoint involved, for Error::Api and Error::InvalidResponse.

Source

pub fn transport_kind(&self) -> Option<TransportErrorKind>

Transport failure classification, if this is a transport error.

Source

pub fn is_timeout(&self) -> bool

Whether the failure was a transport timeout.

Source

pub fn is_retryable(&self) -> bool

Whether the request never reached (or never received an answer from) the gateway’s application layer, so repeating it is safe for read-only endpoints: transport timeouts / connection failures and HTTP 502/503/504.

crate::RetryPolicy consults this. Business errors (Error::Api) and malformed responses are never retryable.

Source

pub fn transport(kind: TransportErrorKind, message: impl Display) -> Self

Build a transport error with a redacted message.

Custom crate::Transport implementations should use this rather than formatting a URL-bearing error into the message.

Source

pub fn http(status: u16, body: &[u8]) -> Self

Build an Error::Http for a non-2xx response, keeping a bounded, redacted preview of body. Custom crate::Transports should use this instead of embedding the raw body.

Source§

impl Error

Well-known configuration and parameter errors.

Source

pub const INVALID_PID: Self

PID must be greater than zero.

Source

pub const INVALID_KEY: Self

Merchant key must not be empty.

Source

pub const INVALID_API_URL: Self

API base URL is malformed or carries credentials, query or fragment.

Source

pub const INSECURE_API_URL: Self

API base URL uses plain HTTP without explicit opt-in.

Source

pub const INVALID_NOTIFY_URL: Self

notify_url is not an absolute HTTP(S) URL.

Source

pub const INVALID_RETURN_URL: Self

return_url is not an absolute HTTP(S) URL.

Source

pub const INSECURE_NOTIFY_URL: Self

notify_url uses plain HTTP without explicit opt-in.

Source

pub const INSECURE_RETURN_URL: Self

return_url uses plain HTTP without explicit opt-in.

Source

pub const MISSING_OUT_TRADE_NO: Self

out_trade_no is empty.

Source

pub const INVALID_OUT_TRADE_NO: Self

out_trade_no violates the accepted charset or length.

Source

pub const MISSING_NOTIFY_URL: Self

Neither the request nor the configuration provides a notify_url.

Source

pub const MISSING_NAME: Self

Product name is blank.

Source

pub const NAME_TOO_LONG: Self

Product name exceeds crate::limits::MAX_NAME_BYTES.

Source

pub const NAME_HAS_CONTROL_CHARS: Self

Product name contains control characters.

Source

pub const SITENAME_HAS_CONTROL_CHARS: Self

sitename contains control characters.

Source

pub const PARAM_TOO_LONG: Self

Source

pub const SITENAME_TOO_LONG: Self

Source

pub const CALLBACK_URL_TOO_LONG: Self

A callback URL exceeds crate::limits::MAX_CALLBACK_URL_BYTES.

Source

pub const REQUEST_TOO_LARGE: Self

The signed request exceeds crate::limits::MAX_REQUEST_BYTES.

Source

pub const INVALID_PAY_TYPE: Self

Payment type is blank or not a short [A-Za-z0-9_-] identifier.

Source

pub const INVALID_DEVICE: Self

device is blank or not a short [A-Za-z0-9_-] identifier.

Source

pub const INVALID_MONEY: Self

Amount is not positive or not parseable.

Source

pub const INVALID_MONEY_PRECISION: Self

Amount carries meaningful precision beyond two decimal places.

Source

pub const MONEY_OUT_OF_RANGE: Self

Amount does not fit the i64 fen range.

Source

pub const MISSING_TRADE_NO: Self

Exactly one of trade_no / out_trade_no must be given.

Source

pub const INVALID_TRADE_NO: Self

trade_no is not a non-blank ASCII identifier.

Source

pub const MISSING_CLIENT_IP: Self

clientip is required by mapi.php.

Source

pub const INVALID_CLIENT_IP: Self

clientip is not a valid IP address.

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

1.30.0 · 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

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more