Skip to content

Commit

Permalink
(Fix) : Rejection handling in VC API
Browse files Browse the repository at this point in the history
  • Loading branch information
protocolwhisper committed Aug 22, 2023
1 parent 802e7ea commit a27b18e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2,015 deletions.
13 changes: 4 additions & 9 deletions common/warp_utils/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ use serde::Serialize;
use warp::reply::{Reply, Response};

/// A convenience wrapper around `blocking_task`.
pub async fn blocking_task<F, T>(func: F) -> Result<Response, warp::Rejection>
pub async fn blocking_task<F, T>(func: F) -> Result<T, warp::Rejection>
where
F: FnOnce() -> Result<T, warp::Rejection> + Send + 'static,
T: Reply + Send + 'static,
T: Send + 'static,
{
let result = tokio::task::spawn_blocking(func)
tokio::task::spawn_blocking(func)
.await
.unwrap_or_else(|_| Err(warp::reject::reject()));
match result {
Ok(reply) => Ok(reply.into_response()),
Err(rejection) => Err(rejection),
}
.unwrap_or_else(|_| Err(warp::reject::reject()))
}

/// A convenience wrapper around `blocking_task` that returns a `warp::reply::Response`.
///
/// Using this method consistently makes it possible to simplify types using `.unify()` or `.uor()`.
Expand Down
Loading

0 comments on commit a27b18e

Please sign in to comment.