Skip to content

Commit

Permalink
handle error better for rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 18, 2024
1 parent 6aab4bf commit 2c62afe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ async fn handle_jsonrpc<T: Default + Metadata>(
};

if let Some(response) = result.await {
(
[(axum::http::header::CONTENT_TYPE, "application/json")],
serde_json::to_string(&response).unwrap(),
)
.into_response()
serde_json::to_string(&response)
.map(|json| {
(
[(axum::http::header::CONTENT_TYPE, "application/json")],
json,
)
.into_response()
})
.unwrap_or_else(|_| StatusCode::INTERNAL_SERVER_ERROR.into_response())
} else {
StatusCode::NO_CONTENT.into_response()
}
Expand Down

0 comments on commit 2c62afe

Please sign in to comment.