Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 34 variants System(String), InvalidCredential(String), InvalidGrantType(String), InvalidAppId(String), InvalidCode(String), InvalidParameter(String), InvalidSecret(String), ForbiddenIp(String), CodeBlocked(String), SecretFrozen(String), MissingAccessToken(String), MissingAppId(String), MissingSecret(String), MissingCode(String), RequiredPostMethod(String), DailyRequestLimitExceeded(String), RateLimitExceeded(String), ForbiddenToken(String), AccountFrozen(String), ThirdPartyToken(String), SessionKeyNotExistedOrExpired(String), InvalidSignatureMethod(String), InvalidSignature(String), ConfirmRequired(String), RequestDeniedOneDay(String), RequestDeniedOneHour(String), Unpad(UnpadError), AesInvalidLength(InvalidLength), Base64Decode(DecodeError), Reqwest(Error), SerdeJson(Error), InternalServer(String), Http(Error), UrlParse(ParseError),
}
Expand description

微信小程序 SDK 错误枚举

包含了所有可能遇到的错误类型,包括微信 API 错误、网络错误、加解密错误等。

§错误分类

§微信 API 错误

这些错误对应微信官方文档中的错误码:

  • InvalidCredential: 凭证无效
  • InvalidCode: 登录 code 无效
  • RateLimitExceeded: API 调用频率限制
  • 等等…

§第三方库错误

自动转换的第三方库错误:

  • Reqwest: HTTP 请求错误
  • SerdeJson: JSON 序列化/反序列化错误
  • Base64Decode: Base64 解码错误
  • AesInvalidLength: AES 加解密长度错误

§系统错误

  • System: 微信系统繁忙
  • InternalServer: 内部服务器错误

§序列化

此枚举使用 thiserror 派生宏,提供了良好的错误消息格式。 每个变体都包含描述性的错误信息。

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

System(String)

微信系统繁忙,请稍候再试

§

InvalidCredential(String)

获取 access_token 时 AppSecret 错误,或者 access_token 无效

§

InvalidGrantType(String)

不合法的凭证类型

§

InvalidAppId(String)

不合法的 AppID,请检查 AppID 的正确性

§

InvalidCode(String)

登录 code 无效或已过期

§

InvalidParameter(String)

请求参数错误

§

InvalidSecret(String)

无效的 appsecret,请检查 appsecret 的正确性

§

ForbiddenIp(String)

IP 地址不在白名单中

§

CodeBlocked(String)

高风险等级用户,小程序登录被拦截

§

SecretFrozen(String)

AppSecret 已被冻结,请登录小程序平台解冻

§

MissingAccessToken(String)

缺少 access_token 参数

§

MissingAppId(String)

缺少 appid 参数

§

MissingSecret(String)

缺少 secret 参数

§

MissingCode(String)

缺少 code 参数

§

RequiredPostMethod(String)

需要 POST 请求

§

DailyRequestLimitExceeded(String)

调用超过天级别频率限制

§

RateLimitExceeded(String)

API 调用太频繁,请稍候再试

§

ForbiddenToken(String)

禁止使用 token 接口

§

AccountFrozen(String)

账号已冻结

§

ThirdPartyToken(String)

第三方平台 API 需要使用第三方平台专用 token

§

SessionKeyNotExistedOrExpired(String)

session_key 不存在或已过期

§

InvalidSignatureMethod(String)

无效的签名方法

§

InvalidSignature(String)

无效的签名

§

ConfirmRequired(String)

此次调用需要管理员确认,请耐心等候

§

RequestDeniedOneDay(String)

该IP调用请求已被公众号管理员拒绝,请24小时后再试

§

RequestDeniedOneHour(String)

该IP调用请求已被公众号管理员拒绝,请1小时后再试

§

Unpad(UnpadError)

AES 解密时数据填充错误

§

AesInvalidLength(InvalidLength)

AES 加解密长度错误

§

Base64Decode(DecodeError)

Base64 解码错误

§

Reqwest(Error)

Reqwet 请求错误

§

SerdeJson(Error)

JSON 序列化/反序列化错误

§

InternalServer(String)

内部服务器错误

§

Http(Error)

HTTP 请求错误

§

UrlParse(ParseError)

Url 解析错误

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<(ErrorCode, String)> for Error

Source§

fn from((code, message): (ErrorCode, String)) -> Self

从微信错误码和消息创建 Error

§参数
  • (code, message): 微信错误码和对应的错误消息
§返回

对应的 Error 枚举变体

Source§

impl From<DecodeError> for Error

Source§

fn from(source: Base64DecodeError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: ReqwestError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: SerdeJsonError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: HttpError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for PagePathError

Source§

fn from(_value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidLength> for Error

Source§

fn from(source: AesInvalidLength) -> Self

Converts to this type from the input type.
Source§

impl From<PagePathError> for Error

Source§

fn from(value: PagePathError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(source: ParseError) -> Self

Converts to this type from the input type.
Source§

impl From<UnpadError> for Error

Source§

fn from(error: UnpadError) -> Self

Converts to this type from the input type.
Source§

impl From<ValidationSceneError> for Error

Source§

fn from(value: ValidationSceneError) -> 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 !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: 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: 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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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

impl<T> ErasedDestructor for T
where T: 'static,