Replace unwraps with proper error handling in fullstack client (#4915) (#4916)

This commit is contained in:
Himmelschmidt authored and GitHub committed 2025-11-05 14:45:21 -03:00
1 parent e03d8ff215
commit 791fa4be7b
1 file changed
+19 -7
+19 -7
View File
@@ -644,7 +644,11 @@ mod browser {
self: Box<Self>, self: Box<Self>,
) -> Pin<Box<dyn Future<Output = Result<Bytes, RequestError>> + Send>> { ) -> Pin<Box<dyn Future<Output = Result<Bytes, RequestError>> + Send>> {
Box::pin(SendWrapper::new(async move { Box::pin(SendWrapper::new(async move {
let bytes = self.inner.binary().await.unwrap(); let bytes = self
.inner
.binary()
.await
.map_err(|e| RequestError::Request(e.to_string()))?;
Ok(bytes.into()) Ok(bytes.into())
})) }))
} }
@@ -653,16 +657,24 @@ mod browser {
self: Box<Self>, self: Box<Self>,
) -> Pin<Box<dyn Stream<Item = Result<Bytes, StreamingError>> + 'static + Unpin + Send>> ) -> Pin<Box<dyn Stream<Item = Result<Bytes, StreamingError>> + 'static + Unpin + Send>>
{ {
let body = match self.inner.body() {
Some(body) => body,
None => {
return Box::pin(SendWrapper::new(futures::stream::iter([Err(
StreamingError::Failed,
)])));
}
};
Box::pin(SendWrapper::new( Box::pin(SendWrapper::new(
wasm_streams::ReadableStream::from_raw(self.inner.body().unwrap()) wasm_streams::ReadableStream::from_raw(body)
.into_stream() .into_stream()
.map(|chunk| { .map(|chunk| {
Ok(chunk let array = chunk
.unwrap() .map_err(|_| StreamingError::Failed)?
.dyn_into::<Uint8Array>() .dyn_into::<Uint8Array>()
.unwrap() .map_err(|_| StreamingError::Failed)?;
.to_vec() Ok(array.to_vec().into())
.into())
}), }),
)) ))
} }