Expand description
A utility crate that converts serde_json::Error into structured, typed errors using the cdumay_error framework. This ensures consistent error handling, easier debugging, and informative error reporting across your Rust applications.
§Features
- Categorizes
serde_json::Errorinto specific error types (Syntax,IO,Data,EOF) - Each error type is associated with a custom code, HTTP status, and descriptive message
- Structured output for APIs, logging systems, and observability platforms
- Includes context metadata via
BTreeMap
§Usage
use cdumay_error::ErrorConverter;
use serde_json::Value;
use std::collections::BTreeMap;
use cdumay_error_json::JsonErrorConverter;
fn parse_json(input: &str) -> Result<Value, cdumay_error::Error> {
serde_json::from_str::<Value>(input).map_err(|e| {
let mut ctx = BTreeMap::new();
ctx.insert("input".to_string(), serde_value::Value::String(input.to_string()));
JsonErrorConverter::convert(&e, "Failed to parse JSON".to_string(), ctx)
})
}Structs§
- Data
Error - EofError
- IoError
- Json
Error Converter - A utility struct for handling JSON errors and converting them into standardized error types.
- Syntax
Error