Skip to content

Commit

Permalink
[aptos-rosetta] Always return 500
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and davidiw committed Sep 4, 2022
1 parent 83a52a8 commit 3cd15bd
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions crates/aptos-rosetta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use warp::{
http::{HeaderValue, Method, StatusCode},
reject::{MethodNotAllowed, PayloadTooLarge, UnsupportedMediaType},
reply, Filter, Rejection, Reply,
};

Expand Down Expand Up @@ -163,37 +162,12 @@ pub fn routes(

/// Handle error codes from warp
async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> {
let code;
let body;

debug!("Failed with: {:?}", err);

if err.is_not_found() {
code = StatusCode::NOT_FOUND;
body = reply::json(&Error::new(code, "Not Found".to_owned()));
} else if let Some(cause) = err.find::<warp::cors::CorsForbidden>() {
code = StatusCode::FORBIDDEN;
body = reply::json(&Error::new(code, cause.to_string()));
} else if let Some(cause) = err.find::<warp::body::BodyDeserializeError>() {
code = StatusCode::BAD_REQUEST;
body = reply::json(&Error::new(code, cause.to_string()));
} else if let Some(cause) = err.find::<warp::reject::LengthRequired>() {
code = StatusCode::LENGTH_REQUIRED;
body = reply::json(&Error::new(code, cause.to_string()));
} else if let Some(cause) = err.find::<PayloadTooLarge>() {
code = StatusCode::PAYLOAD_TOO_LARGE;
body = reply::json(&Error::new(code, cause.to_string()));
} else if let Some(cause) = err.find::<UnsupportedMediaType>() {
code = StatusCode::UNSUPPORTED_MEDIA_TYPE;
body = reply::json(&Error::new(code, cause.to_string()));
} else if let Some(cause) = err.find::<MethodNotAllowed>() {
code = StatusCode::METHOD_NOT_ALLOWED;
body = reply::json(&Error::new(code, cause.to_string()));
} else {
code = StatusCode::INTERNAL_SERVER_ERROR;
body = reply::json(&Error::new(code, format!("unexpected error: {:?}", err)));
}
let mut rep = reply::with_status(body, code).into_response();
let body = reply::json(&Error::new(
StatusCode::INTERNAL_SERVER_ERROR,
format!("unexpected error: {:?}", err),
));
let mut rep = reply::with_status(body, StatusCode::INTERNAL_SERVER_ERROR).into_response();
rep.headers_mut()
.insert("access-control-allow-origin", HeaderValue::from_static("*"));
Ok(rep)
Expand Down

0 comments on commit 3cd15bd

Please sign in to comment.