Skip to main content

error_json

Function error_json 

Source
pub fn error_json(err: &(dyn Error + 'static), error_type: &str) -> Value
Expand description

Build the canonical JSON error envelope for an error: { "error": { "type": …, "message": … } }.

The inner object always carries a machine-readable type discriminator (so consumers can branch on the kind of failure without parsing the message) and at least a message string. When the error chain contains a JSON-RPC ErrorObject (whose own Display is just its debug representation), its structured { code, message, data? } form is merged in; every other error falls back to its Display as the message.

error_type is the caller-supplied discriminator (e.g. "sac_not_deployed", or "unknown" when the error has no more specific type).