Crates.io | jsonerr |
lib.rs | jsonerr |
version | 0.0.3 |
source | src |
created_at | 2023-05-13 07:18:06.346647 |
updated_at | 2023-06-02 20:00:46.147142 |
description | jsonerr macro and builder |
homepage | https://codeberg.org/AlbanMinassian/errorjson |
repository | https://codeberg.org/AlbanMinassian/errorjson |
max_upload_size | |
id | 863594 |
size | 16,980 |
jsonerr help to crate json error
use jsonerr::*;
fn main() {
let myjson = jsonerr!(code = "ERR001", message = "An error message");
println!("{:#?}", myjson);
}
return
{
"iserr":true,
"err":{
"code":"ERR001",
"message":"An error message"
}
}
use jsonerr::*;
fn main() {
let error = "NaN".parse::<u32>().unwrap_err();
let myjson = jsonerr!(
code = "ERR002",
message = "An error message",
origin = error // <-- 'std::error::Error' only
);
println!("{:#?}", myjson);
}
return
{
"iserr":true,
"err":{
"code":"ERR003",
"message":"An error message",
"origin": "invalid digit found in string"
}
}
If error message string like a json (example {"deep":"caused error","test":1}
)
{
"iserr":true,
"err":{
"code":"ERR003",
"message":"An error message",
"origin": {
"deep": "caused error",
"test": 1
}
}
}
use jsonerr::*;
fn main() {
let myjson = jsonerr!(
code = "ERR002",
message = "An error message",
payload = serde_json::json!({ "more": "data" }) // <-- 'serde_json::Value' only
);
println!("{:#?}", myjson);
}
return
{
"iserr":true,
"err":{
"code":"ERR003",
"message":"An error message",
"payload": { "more": "data" }
}
}
cargo run --example basic
.meta
, .err
and .iserr
.err
with always .code
, .message
, .origin
, payload