Skip to main content

error_reply_with_data

Function error_reply_with_data 

Source
pub fn error_reply_with_data(
    id: &WireId<'_>,
    code: IrErrorCode,
    message: &str,
    data: &JsonObject,
) -> Value
Expand description

A failed reply carrying the structured data some codes require.

SEP-2575’s -32022 is the case this exists for: its data names the revision the client asked for and every revision this server speaks, and a client cannot retry correctly without both. error_reply cannot express that, so this is a second function rather than an optional argument on the first — every other error in the crate has no data, and a parameter they would all pass None to is a parameter nobody reads.

§Examples

use protocol_droid::domain::jsonrpc::reply::error_reply_with_data;
use protocol_droid::domain::ir::{IrErrorCode, JsonObject};
use protocol_droid::domain::jsonrpc::WireId;

let data = JsonObject::new(r#"{"requested":"2027-01-01","supported":["2026-07-28"]}"#)?;
let document =
    error_reply_with_data(&WireId::text("r1"), IrErrorCode::UNSUPPORTED_PROTOCOL_VERSION,
        "unsupported version", &data).to_string();

assert!(document.contains(r#""code":-32022"#));
assert!(document.contains(r#""supported":["2026-07-28"]"#));