mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Remove VC response signing and fix HTTP error handling (#5529)
* and_then to then remove expect move convert_rejection to utils remove signer from vc api * remove key * remove auth header * revert * Merge branch 'unstable' of https://github.com/sigp/lighthouse into vc-api-fix * merge unstable * revert * Merge branch 'unstable' of https://github.com/sigp/lighthouse into vc-api-fix * Merge branch 'unstable' of https://github.com/sigp/lighthouse into vc-api-fix * refactor blocking json task * linting * revert logging * remove response signing checks in validtor http_api client * remove notion of public key, prefixes, and simplify token generation * fmt * Remove outdated comment on public key
This commit is contained in:
@@ -2,7 +2,7 @@ use eth2::types::{ErrorMessage, Failure, IndexedErrorMessage};
|
||||
use std::convert::Infallible;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use warp::{http::StatusCode, reject::Reject};
|
||||
use warp::{http::StatusCode, reject::Reject, reply::Response, Reply};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ServerSentEventError(pub String);
|
||||
@@ -255,3 +255,21 @@ pub async fn handle_rejection(err: warp::Rejection) -> Result<impl warp::Reply,
|
||||
|
||||
Ok(warp::reply::with_status(json, code))
|
||||
}
|
||||
|
||||
/// Convert a warp `Rejection` into a `Response`.
|
||||
///
|
||||
/// This function should *always* be used to convert rejections into responses. This prevents warp
|
||||
/// from trying to backtrack in strange ways. See: https://github.com/sigp/lighthouse/issues/3404
|
||||
pub async fn convert_rejection<T: Reply>(res: Result<T, warp::Rejection>) -> Response {
|
||||
match res {
|
||||
Ok(response) => response.into_response(),
|
||||
Err(e) => match handle_rejection(e).await {
|
||||
Ok(reply) => reply.into_response(),
|
||||
Err(_) => warp::reply::with_status(
|
||||
warp::reply::json(&"unhandled error"),
|
||||
eth2::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
.into_response(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::reject::convert_rejection;
|
||||
use serde::Serialize;
|
||||
use warp::reply::{Reply, Response};
|
||||
|
||||
@@ -24,14 +25,16 @@ where
|
||||
}
|
||||
|
||||
/// A convenience wrapper around `blocking_task` for use with `warp` JSON responses.
|
||||
pub async fn blocking_json_task<F, T>(func: F) -> Result<Response, warp::Rejection>
|
||||
pub async fn blocking_json_task<F, T>(func: F) -> Response
|
||||
where
|
||||
F: FnOnce() -> Result<T, warp::Rejection> + Send + 'static,
|
||||
T: Serialize + Send + 'static,
|
||||
{
|
||||
blocking_response_task(|| {
|
||||
let result = blocking_response_task(|| {
|
||||
let response = func()?;
|
||||
Ok(warp::reply::json(&response))
|
||||
})
|
||||
.await
|
||||
.await;
|
||||
|
||||
convert_rejection(result).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user