코드 4-28 매개변수 추출 에러 처리하기
use warp::{http::StatusCode, reject::Reject, Filter, Rejection, Reply};
...
async fn return_error(r: Rejection) -> Result<impl Reply, Rejection> {
if let Some(error) = r.find::<Error>() {
Ok(warp::reply::with_status(
error.to_string(),
StatusCode::RANGE_NOT_SATISFIABLE,
))
} else if let Some(error) = r.find::<CorsForbidden>() {
Ok(warp::reply::with_status(
error.to_string(),
StatusCode::FORBIDDEN,
))
} else {
Ok(warp::reply::with_status(
"Route not found".to_string(),
StatusCode::NOT_FOUND,
))
}
}
...