-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starknet_gateway_types,starknet_http_server): move spec error co…
…nversion to the http server
- Loading branch information
1 parent
a422bb3
commit 03b0b7e
Showing
5 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,48 @@ | ||
use axum::response::{IntoResponse, Response}; | ||
use jsonrpsee::types::error::ErrorCode; | ||
use starknet_gateway_types::communication::GatewayClientError; | ||
use starknet_gateway_types::errors::GatewayError; | ||
use thiserror::Error; | ||
use tracing::error; | ||
|
||
/// Errors originating from `[`HttpServer::run`]` command. | ||
#[derive(Debug, Error)] | ||
pub enum HttpServerRunError { | ||
#[error(transparent)] | ||
ServerStartupError(#[from] hyper::Error), | ||
} | ||
|
||
/// Wraps the `GatewayClientError` in order to implement Axum's `IntoResponse` trait. | ||
#[derive(Error, Debug)] | ||
#[error(transparent)] | ||
pub struct GatewayClientErrorWrapper(#[from] GatewayClientError); | ||
|
||
impl IntoResponse for GatewayClientErrorWrapper { | ||
fn into_response(self) -> Response { | ||
let general_rpc_error = match self.0 { | ||
GatewayClientError::ClientError(e) => { | ||
error!("Got a gateway client: {}", e); | ||
jsonrpsee::types::ErrorObject::owned( | ||
ErrorCode::InternalError.code(), | ||
"Internal error", | ||
None::<()>, | ||
) | ||
} | ||
GatewayClientError::GatewayError(GatewayError::GatewaySpecError { | ||
source, | ||
p2p_message_metadata: _, | ||
}) => { | ||
let rpc_spec_error = source.into_rpc(); | ||
jsonrpsee::types::ErrorObject::owned( | ||
ErrorCode::ServerError(rpc_spec_error.code).code(), | ||
rpc_spec_error.message, | ||
rpc_spec_error.data, | ||
) | ||
} | ||
}; | ||
|
||
serde_json::to_vec(&general_rpc_error) | ||
.expect("Expecting a serializable error.") | ||
.into_response() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters