我想知道如何在 Warp 的拒绝处理程序中获取 HTTP 路径?我有以下拒绝方法:
pub(crate) async fn handle(err: Rejection) -> Result<impl Reply, Infallible> {
let response = if err.is_not_found() {
HttpApiProblem::with_title_and_type_from_status(StatusCode::NOT_FOUND)
} else if let Some(e) = err.find::<warp::filters::body::BodyDeserializeError>() {
HttpApiProblem::with_title_and_type_from_status(StatusCode::BAD_REQUEST)
.set_detail(format!("{}", e))
} else if let Some(e) = err.find::<Error>() {
handle_request_error(e)
} else if let Some(e) = err.find::<warp::reject::MethodNotAllowed>() {
HttpApiProblem::with_title_and_type_from_status(StatusCode::METHOD_NOT_ALLOWED)
.set_detail(format!("{}", e))
} else {
error!("handle_rejection catch all: {:?}", err);
HttpApiProblem::with_title_and_type_from_status(StatusCode::INTERNAL_SERVER_ERROR)
};
Ok(response.to_hyper_response())
}
例如,我会打电话curl localhost:1234/this-aint-valid-path/123
并希望能够访问以/this-aint-valid-path/123
进行日志记录,并将其作为错误响应的一部分返回。