| Crates.io | terror |
| lib.rs | terror |
| version | 3.1.0 |
| created_at | 2022-05-17 21:45:30.606341+00 |
| updated_at | 2025-08-19 11:08:00.442349+00 |
| description | Uniform REST error response body, tailored for JSON |
| homepage | |
| repository | https://github.com/artkonr/terror |
| max_upload_size | |
| id | 588629 |
| size | 36,476 |
TError (as in Typical Error) is a small library that exposes a configurable and uniform response body representation for typical REST services. It covers most basic aspects such as returned status code, messages, detailed error data and so on.
To enable terror, simply add it to your Cargo.toml:
terror = "3.1.0"
And then start hacking in the code:
fn main() {
let error = Terror::new(500, String::format("generic server error"))
.build();
}
You can also add some flavour to it, for example, an error code:
fn main() {
let error = Terror::new(500, String::format("generic server error"))
.error_code("error.internal")
.build();
}
terror is built with Rust 1.70.
It's a general intention of terror to be serialized into JSON. Therefore, it's designed to be compatible with
serde. As for the rest, terror tries to enforce as little dependencies as possible.
It's sometimes convenient to add some extra metadata to your error responses; terror offers 3 such things
out-of-the-box:
| feature | notion | backend |
|---|---|---|
err_id |
V4 UUID error ID | uuid |
time |
ISO-8601 error timestamp at UTC | chrono |
mdn |
a link to MDN reference about status code | n/a |