use std::convert::Infallible;
use bytes::Bytes;
use http_body_util::combinators::BoxBody;
use a2a_protocol_types::error::ErrorCode;
use super::JsonRpcDispatcher;
use super::response::{error_response, invalid_request_response, parse_error_response};
use crate::error::ServerError;
impl JsonRpcDispatcher {
pub(super) fn refuse(
&self,
started: std::time::Instant,
err: &ServerError,
) -> hyper::Response<BoxBody<Bytes, Infallible>> {
self.record_unrouted(started, err.to_a2a_error().code);
error_response(None, err)
}
pub(super) fn refuse_unparsed(
&self,
started: std::time::Instant,
message: &str,
) -> hyper::Response<BoxBody<Bytes, Infallible>> {
self.record_unrouted(started, ErrorCode::ParseError);
parse_error_response(None, message)
}
pub(super) fn refuse_invalid(
&self,
started: std::time::Instant,
message: &str,
) -> hyper::Response<BoxBody<Bytes, Infallible>> {
self.record_unrouted(started, ErrorCode::InvalidRequest);
invalid_request_response(None, message)
}
pub(super) fn record_unrouted(&self, started: std::time::Instant, code: ErrorCode) {
crate::rpc_span::record_unrouted(
&self.handler,
crate::rpc_span::RpcSystem::JsonRpc,
started,
&code.as_i32().to_string(),
);
}
}