macro_rules! blame_err {
(client, $err:expr) => { ... };
(client, $code:literal, $err:expr) => { ... };
(server, $err:expr) => { ... };
(server, $code:literal, $err:expr) => { ... };
}
Expand description
Creates a new [GenericErrorWithCause
(the error type behind
RenderFnResultWithCause
) efficiently.
This allows you to explicitly return errors from any state-generation
functions, including both an error and a statement of whether the server or
the client is responsible. With this macro, you can use any of the following
syntaxes (substituting "error!"
for any error that can be converted with
.into()
into a Box<dyn std::error::Error>
):
blame_err!(client, "error!")
– an error that’s the client’s fault, with the default HTTP status code (400, a generic client error)blame_err!(server, "error!")
– an error that’s the server’s fault, with the default HTTP status code (500, a generic server error)blame_err!(client, 404, "error!")
– an error that’s the client’s fault, with a custom HTTP status code (404 in this example)blame_err!(server, 501, "error!")
– an error that’s the server’s fault, with a custom HTTP status code (501 in this example)
Note that this macro will automatically return
the error it creates.