Skip to content

Commit 19915e0

Browse files
authored
Merge pull request #15 from wandercn/myerror
update
2 parents cda7249 + 29f27a7 commit 19915e0

File tree

9 files changed

+204
-181
lines changed

9 files changed

+204
-181
lines changed

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "alipay_sdk_rust"
33
license = "MIT"
4-
version = "1.0.12"
4+
version = "1.0.13"
55
edition = "2018"
66
authors = ["wandercn<[email protected]>"]
77
description = "AliPay Sdk for Rust"
@@ -14,12 +14,14 @@ categories = ["api-bindings", "accessibility", "development-tools", "compilers"]
1414
jsonmap = "0.1"
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1.0"
17-
gostd = "0.3.19"
17+
gostd = "0.4.1"
1818
sha2 = "0.10.2"
19-
base64 = "0.13.0"
19+
base64 = "0.22.1"
2020
rsa = "0.6.1"
2121
uuid = { version = "1.0.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
2222
serde_with = "1.14.0"
2323
log = "0.4"
24-
x509-parser = "0.16.0"
24+
x509-parser = "0.17.0"
2525
md5 = "0.7.0"
26+
thiserror ="2.0"
27+
anyhow= "1.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [x] BizContenter trait 对应的set 方法设支持vlaue值可以是字符串,整型和浮点型,数组和对象同时存储在一个HashMap中。版本:v1.0.5
2323
- [x] 适配最新的沙箱环境测试 版本:v1.0.5
2424
- [x] async_verify_sign 增加了异步通知验签函数 版本:v1.0.8
25+
- [x] 增加了自定义错误进行错误处理 版本:v1.0.8
2526

2627
# Example
2728
## apidoc

src/error.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::{str::Utf8Error, string::FromUtf8Error};
2+
3+
use anyhow::Result;
4+
use gostd::net::http::HTTPConnectError;
5+
use thiserror::Error;
6+
// 自定义错误类型 AlipaySDKError
7+
#[derive(Debug, Error)]
8+
pub enum AliPaySDKError {
9+
#[error("IO error: {0}")]
10+
Io(#[from] std::io::Error),
11+
12+
#[error("HTTP connection error: {0}")]
13+
HttpConnection(#[from] HTTPConnectError),
14+
15+
#[error("Alipay error: {0}")]
16+
AliPayError(String),
17+
18+
#[error("Utf8Error{0}")]
19+
Utf8Error(#[from] Utf8Error),
20+
21+
#[error("FromUtf8Error: {0}")]
22+
FromUtf8Error(#[from] FromUtf8Error),
23+
24+
#[error("serde json error{0}")]
25+
JsonError(#[from] serde_json::Error),
26+
}
27+
28+
impl From<String> for AliPaySDKError {
29+
fn from(err: String) -> Self {
30+
AliPaySDKError::AliPayError(err)
31+
}
32+
}
33+
34+
impl From<&str> for AliPaySDKError {
35+
fn from(err: &str) -> Self {
36+
AliPaySDKError::AliPayError(err.to_owned())
37+
}
38+
}
39+
40+
pub type AliPayResult<T> = Result<T, AliPaySDKError>;

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
//! (如下的Example使用的是沙箱环境下本人申请的自定义公钥证书) (已经适配新版沙箱环境,新版沙箱网关地址是https://openapi-sandbox.dl.alipaydev.com/gateway.do)
2222
//!
2323
//! ```rust
24-
//! use std::io::Result;
24+
//! use alipay_sdk_rust::error::AliPayResult;
2525
//! use alipay_sdk_rust::biz::{self, BizContenter};
2626
//! use alipay_sdk_rust::pay::{PayClient, Payer};
2727
//! use alipay_sdk_rust::response::TradeCreateResponse;
28-
//! fn main() -> Result<()> {
28+
//! fn main() -> AliPayResult<()> {
2929
//! let out_trade_no = gostd::time::Now().UnixNano().to_string();
3030
//! let mut biz_content = biz::TradeCreateBiz::new();
3131
//! biz_content.set_subject("huawei Mate50".into());
@@ -40,7 +40,7 @@
4040
//! Ok(())
4141
//! }
4242
//!
43-
//! fn new_pay_client() -> Result<impl Payer> {
43+
//! fn new_pay_client() -> AliPayResult<impl Payer> {
4444
//! let client = PayClient::builder()
4545
//! .api_url("https://openapi-sandbox.dl.alipaydev.com/gateway.do")
4646
//! .app_id("9021000138690920")
@@ -65,11 +65,11 @@
6565
//! `
6666
pub mod biz;
6767
pub mod cert;
68+
pub mod error;
6869
pub mod pay;
6970
pub mod request;
7071
pub mod response;
7172
pub mod sign;
72-
pub mod util;
73-
7473
#[cfg(test)]
7574
mod tests;
75+
pub mod util;

0 commit comments

Comments
 (0)