pub struct Builder { /* private fields */ }
Expand description

A builder for Terror. Intended for one-time used, consumed after calling Builder::build.

Implementations

Adds a short error message.

Adds a short error message.

Adds an error code.

Adds an error code.

Adds a text detail.

Examples

For instance,

use terror::{Builder, Terror};
let built = Terror::new(500, String::from("generic error"))
    .add_text_detail(String::from("object_name"), String::from("server"))
    .build();

… may be rendered into a JSON like below:

{
    "status" : 500,
    "message" : "generic error",
    "details" : {
        "object_name" : "server"
    }
}

A shorthand for Builder::add_text_detail, which allows to pass the key name as &str.

Adds a numeric detail.

Examples

For instance,

use terror::{Builder, Terror};
let built = Terror::new(500, String::from("generic error"))
    .add_int_detail(String::from("object_id"), 922i64)
    .build();

… may be rendered into a JSON like below:

{
    "status" : 500,
    "message" : "generic error",
    "details" : {
        "object_id" : 922
    }
}

A shorthand for Builder::add_int_detail, which allows to pass the key name as &str.

Adds a boolean detail.

Examples

For instance,

use terror::{Builder, Terror};
let built = Terror::new(500, String::from("generic error"))
    .add_bool_detail(String::from("object_up"), false)
    .build();

… may be rendered into a JSON like below:

{
    "status" : 500,
    "message" : "generic error",
    "details" : {
        "object_up" : false
    }
}

A shorthand for Builder::add_bool_detail, which allows to pass the key name as &str.

Adds an arbitrary object as detail. Requires to be passed as a pointer.

Examples

For instance,

use terror::{Builder, Terror};
use serde_json::{json, Value};

let built = Terror::new(500, String::from("generic error"))
    .add_value_detail(
        String::from("object"),
        Value::from(json!({
            "id" : 94i32,
            "name" : "server"
        }))
    )
    .build();

… may be rendered into a JSON like below:

{
    "status" : 500,
    "message" : "generic error",
    "details" : {
        "object" : {
            "id" : 94,
            "name" : "server"
        }
    }
}

A shorthand for Builder::add_value_detail, which allows to pass the key name as &str.

Instructs the builder to attach a reference to MDN page explaining the HTTP status code.

Concludes the configuration and produces a new Terror instance with all ownerships transferred, thus fully consuming self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.