Skip to content

Commit

Permalink
Merge pull request #521 from chainbound/chore/more-errors
Browse files Browse the repository at this point in the history
chore: use more specific error types
  • Loading branch information
merklefruit authored Dec 6, 2024
2 parents c18f442 + 3623003 commit 08182a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions bolt-sidecar/src/api/commitments/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ pub async fn rpc_entrypoint(
};

// Parse the inclusion request from the parameters
let mut inclusion_request: InclusionRequest = serde_json::from_value(request_json)
.map_err(|e| RejectionError::ValidationFailed(e.to_string()))
.inspect_err(|e| error!("Failed to parse inclusion request: {:?}", e))?;
let mut inclusion_request = serde_json::from_value::<InclusionRequest>(request_json)
.map_err(RejectionError::Json)
.inspect_err(|err| error!(?err, "Failed to parse inclusion request"))?;

debug!(?inclusion_request, "New inclusion request");

Expand Down
13 changes: 11 additions & 2 deletions bolt-sidecar/src/api/commitments/spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use alloy::primitives::SignatureError;
use axum::{extract::rejection::JsonRejection, http::StatusCode, response::IntoResponse, Json};
use axum::{
body::Body,
extract::rejection::JsonRejection,
http::{Response, StatusCode},
response::IntoResponse,
Json,
};
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -58,7 +64,7 @@ pub enum CommitmentError {
}

impl IntoResponse for CommitmentError {
fn into_response(self) -> axum::http::Response<axum::body::Body> {
fn into_response(self) -> Response<Body> {
match self {
Self::Rejected(err) => {
(StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32000, err.to_string())))
Expand Down Expand Up @@ -117,6 +123,9 @@ pub enum RejectionError {
/// State validation failed for this request.
#[error("Validation failed: {0}")]
ValidationFailed(String),
/// JSON parsing error.
#[error("JSON parsing error: {0}")]
Json(#[from] serde_json::Error),
}

/// Implements the commitments-API: <https://chainbound.github.io/bolt-docs/api/rpc>
Expand Down

0 comments on commit 08182a5

Please sign in to comment.