Skip to content

Commit c21d9a3

Browse files
committed
sdk: Use SdkApiError
1 parent 30ac298 commit c21d9a3

File tree

8 files changed

+30
-28
lines changed

8 files changed

+30
-28
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lexe-api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ lexe-tokio.path = "../lexe-tokio"
3535
anyhow.workspace = true
3636
axum = { workspace = true, features = ["json", "query"] }
3737
axum-server.workspace = true
38-
base64.workspace = true
3938
bcs.workspace = true
4039
bytes.workspace = true
4140
http.workspace = true

sdk-core/src/def.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
// We don't export our traits currently so auto trait stability is not relevant.
77
#![allow(async_fn_in_trait)]
88

9-
use crate::{
10-
SdkApiError,
11-
models::{
12-
SdkCreateInvoiceRequest, SdkCreateInvoiceResponse,
13-
SdkGetPaymentRequest, SdkGetPaymentResponse, SdkNodeInfoResponse,
14-
SdkPayInvoiceRequest, SdkPayInvoiceResponse,
15-
},
9+
use lexe_api_core::error::SdkApiError;
10+
11+
use crate::models::{
12+
SdkCreateInvoiceRequest, SdkCreateInvoiceResponse, SdkGetPaymentRequest,
13+
SdkGetPaymentResponse, SdkNodeInfoResponse, SdkPayInvoiceRequest,
14+
SdkPayInvoiceResponse,
1615
};
1716

1817
/// The API exposed to SDK users.

sdk-core/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,3 @@ pub mod def;
88
pub mod models;
99
/// Shared API types.
1010
pub mod types;
11-
12-
// TODO(max): Replace these with LexeError
13-
/// Temporary type alias for the errors returned by SDK APIs.
14-
pub type SdkApiError = lexe_api_core::error::NodeApiError;
15-
/// Temporary type alias for the error kinds returned by SDK APIs.
16-
pub type SdkErrorKind = lexe_api_core::error::NodeErrorKind;

sdk-sidecar/src/client.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use lexe_api::{rest::RestClient, types::Empty};
1+
use lexe_api::{
2+
error::{SdkApiError, SdkErrorKind},
3+
rest::RestClient,
4+
types::Empty,
5+
};
26
use sdk_core::{
3-
SdkApiError, SdkErrorKind,
47
def::SdkApi,
58
models::{
69
SdkCreateInvoiceRequest, SdkCreateInvoiceResponse,

sdk-sidecar/src/def.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
// We don't export our traits currently so auto trait stability is not relevant.
77
#![allow(async_fn_in_trait)]
88

9+
use lexe_api::error::SdkApiError;
910
#[cfg(doc)]
1011
use lexe_api::types::Empty;
11-
use sdk_core::{SdkApiError, def::SdkApi};
12+
use sdk_core::def::SdkApi;
1213

1314
use crate::api::HealthCheckResponse;
1415

sdk-sidecar/src/extract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use anyhow::Context;
44
use axum::extract::FromRequestParts;
55
use common::{ed25519, rng::SysRng};
66
use http::header::AUTHORIZATION;
7+
use lexe_api::error::SdkApiError;
78
use node_client::{
89
client::{GatewayClient, NodeClient},
910
credentials::{ClientCredentials, Credentials},
1011
};
11-
use sdk_core::SdkApiError;
1212

1313
use crate::server::RouterState;
1414

sdk-sidecar/src/server.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ use axum::{
1111
use common::{ed25519, env::DeployEnv};
1212
use lexe_api::{
1313
def::AppNodeRunApi,
14-
error::NodeErrorKind,
14+
error::{SdkApiError, SdkErrorKind},
1515
models::command::{CreateInvoiceResponse, LxPaymentIdStruct},
1616
server::{LxJson, extract::LxQuery},
1717
types::payments::PaymentCreatedIndex,
1818
};
1919
use node_client::client::NodeClient;
2020
use quick_cache::unsync;
2121
use sdk_core::{
22-
SdkApiError,
2322
models::{
2423
SdkCreateInvoiceRequest, SdkCreateInvoiceResponse,
2524
SdkGetPaymentRequest, SdkGetPaymentResponse, SdkNodeInfoResponse,
@@ -121,11 +120,11 @@ mod node {
121120
State(_): State<Arc<RouterState>>,
122121
NodeClientExtractor(node_client): NodeClientExtractor,
123122
) -> Result<LxJson<SdkNodeInfoResponse>, SdkApiError> {
124-
node_client
123+
let info = node_client
125124
.node_info()
126125
.await
127-
.map(SdkNodeInfoResponse::from)
128-
.map(LxJson)
126+
.map_err(SdkApiError::command)?;
127+
Ok(LxJson(SdkNodeInfoResponse::from(info)))
129128
}
130129

131130
#[instrument(skip_all, name = "(create-invoice)")]
@@ -137,7 +136,10 @@ mod node {
137136
let CreateInvoiceResponse {
138137
invoice,
139138
created_index: maybe_index,
140-
} = node_client.create_invoice(req.into()).await?;
139+
} = node_client
140+
.create_invoice(req.into())
141+
.await
142+
.map_err(SdkApiError::command)?;
141143

142144
let index = maybe_index
143145
.ok_or("Node out-of-date. Upgrade to node-v0.8.10 or later.")
@@ -153,7 +155,11 @@ mod node {
153155
LxJson(req): LxJson<SdkPayInvoiceRequest>,
154156
) -> Result<LxJson<SdkPayInvoiceResponse>, SdkApiError> {
155157
let id = req.invoice.payment_id();
156-
let created_at = node_client.pay_invoice(req.into()).await?.created_at;
158+
let created_at = node_client
159+
.pay_invoice(req.into())
160+
.await
161+
.map_err(SdkApiError::command)?
162+
.created_at;
157163
let resp = SdkPayInvoiceResponse {
158164
index: PaymentCreatedIndex { id, created_at },
159165
created_at,
@@ -174,7 +180,7 @@ mod node {
174180
Ok(LxJson(payment)) => Ok(LxJson(SdkGetPaymentResponse {
175181
payment: Some(payment),
176182
})),
177-
Err(e) if e.kind == NodeErrorKind::NotFound =>
183+
Err(e) if e.kind == SdkErrorKind::NotFound =>
178184
Ok(LxJson(SdkGetPaymentResponse { payment: None })),
179185
Err(e) => Err(e),
180186
}
@@ -200,7 +206,8 @@ mod node {
200206

201207
let maybe_basic_payment = node_client
202208
.get_payment_by_id(LxPaymentIdStruct { id })
203-
.await?
209+
.await
210+
.map_err(SdkApiError::command)?
204211
.maybe_payment;
205212

206213
let basic_payment = match maybe_basic_payment {

0 commit comments

Comments
 (0)