-
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
4fb7a41
commit 557330f
Showing
5 changed files
with
57 additions
and
30 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,54 @@ | ||
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), | ||
} | ||
|
||
/// Errors that may occure during the runtime of the HTTP server. | ||
#[derive(Error, Debug)] | ||
pub enum HttpServerError { | ||
#[error(transparent)] | ||
GatewayClientError(#[from] GatewayClientError), | ||
} | ||
|
||
impl IntoResponse for HttpServerError { | ||
fn into_response(self) -> Response { | ||
match self { | ||
HttpServerError::GatewayClientError(e) => gw_client_err_into_response(e), | ||
} | ||
} | ||
} | ||
|
||
fn gw_client_err_into_response(err: GatewayClientError) -> Response { | ||
let general_rpc_error = match err { | ||
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