Skip to content

Commit ca94b74

Browse files
committed
Refactor error handling in MakeRequest to use ServerFnError for improved consistency
1 parent d1deb3c commit ca94b74

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

frontend/common/src/utils/client/make_request.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use leptos::server_fn::{
77
ServerFn,
88
ServerFnError,
99
client::browser::BrowserClient,
10-
codec::{Encoding, FromReq, GetUrl, IntoReq, PostUrl},
10+
codec::{FromReq, GetUrl, IntoReq, PostUrl},
1111
middleware::Layer,
1212
request::{ClientReq, browser::BrowserRequest},
1313
};
@@ -35,7 +35,7 @@ where
3535
E::ResponseBody: Serialize + DeserializeOwned,
3636
{
3737
type Client = BrowserClient;
38-
type Error = ErrorType;
38+
type Error = ServerFnError<ErrorType>;
3939
type InputEncoding = ApiEncoding<E>;
4040
type Output = AppResponse<E>;
4141
type OutputEncoding = ApiEncoding<E>;
@@ -51,7 +51,7 @@ where
5151
const PATH: &'static str = <E::RequestPath as TypedPath>::PATH;
5252

5353
#[cfg(not(target_arch = "wasm32"))]
54-
async fn run_body(self) -> Result<Self::Output, ServerFnError<Self::Error>> {
54+
async fn run_body(self) -> Result<Self::Output, Self::Error> {
5555
use std::net::{IpAddr, SocketAddr};
5656

5757
use axum::extract::ConnectInfo;
@@ -65,7 +65,8 @@ where
6565

6666
let ConnectInfo(socket_addr) = leptos_axum::extract::<ConnectInfo<SocketAddr>>()
6767
.await
68-
.map_err(ErrorType::server_error)?;
68+
.map_err(ErrorType::server_error)
69+
.map_err(ServerFnError::WrappedServerError)?;
6970
let layer = super::API_CALL_REGISTRY
7071
.get()
7172
.expect("API call registry not initialized")
@@ -100,7 +101,7 @@ where
100101
}
101102

102103
#[cfg(target_arch = "wasm32")]
103-
async fn run_body(self) -> Result<Self::Output, ServerFnError<Self::Error>> {
104+
async fn run_body(self) -> Result<Self::Output, Self::Error> {
104105
unreachable!()
105106
}
106107

@@ -109,7 +110,7 @@ where
109110
}
110111
}
111112

112-
impl<E> IntoReq<ApiEncoding<E>, BrowserRequest, ErrorType> for MakeRequest<E>
113+
impl<E> IntoReq<ApiEncoding<E>, BrowserRequest, ServerFnError<ErrorType>> for MakeRequest<E>
113114
where
114115
E: ApiEndpoint,
115116
<E::RequestBody as Preprocessable>::Processed: Send,
@@ -142,7 +143,8 @@ where
142143
}
143144

144145
#[cfg(not(target_arch = "wasm32"))]
145-
impl<E> FromReq<ApiEncoding<E>, http::Request<axum::body::Body>, ErrorType> for MakeRequest<E>
146+
impl<E> FromReq<ApiEncoding<E>, http::Request<axum::body::Body>, ServerFnError<ErrorType>>
147+
for MakeRequest<E>
146148
where
147149
E: ApiEndpoint,
148150
<E::RequestBody as Preprocessable>::Processed: Send,
@@ -157,7 +159,8 @@ where
157159
}
158160

159161
#[cfg(target_arch = "wasm32")]
160-
impl<E> FromReq<ApiEncoding<E>, leptos::server_fn::request::BrowserMockReq, ErrorType>
162+
impl<E>
163+
FromReq<ApiEncoding<E>, leptos::server_fn::request::BrowserMockReq, ServerFnError<ErrorType>>
161164
for MakeRequest<E>
162165
where
163166
E: ApiEndpoint,

0 commit comments

Comments
 (0)