Skip to content

Commit

Permalink
charms server: return 404 only if the spell really isn't there
Browse files Browse the repository at this point in the history
(part 2)
  • Loading branch information
imikushin committed Dec 30, 2024
1 parent e40259f commit 042c0da
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/cli/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{cli::ServerConfig, spell::Spell, tx::spell_and_proof};
use anyhow::Result;
use axum::{http::StatusCode, routing::get, Json, Router};
use bitcoincore_rpc::{Auth, Client, RpcApi};
use bitcoincore_rpc::{jsonrpc::Error::Rpc, Auth, Client, RpcApi};
use serde::{Deserialize, Serialize};
use std::{str::FromStr, sync::OnceLock};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
Expand Down Expand Up @@ -76,9 +76,14 @@ fn get_spell(txid: &str) -> Result<Spell, StatusCode> {
None => Err(StatusCode::NOT_FOUND),
Some((s, _)) => Ok(Spell::denormalized(&s)),
},
Err(e) => {
eprintln!("Error fetching transaction: {}", e);
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
Err(e) => match e {
bitcoincore_rpc::Error::JsonRpc(Rpc(rpc_error)) if rpc_error.code == -5 => {
Err(StatusCode::NOT_FOUND)
}
_ => {
eprintln!("Error: {:?}", e);
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
},
}
}

0 comments on commit 042c0da

Please sign in to comment.