apikit/
reply.rs

1//! Shorthand reply utilities.
2use axum::http::StatusCode;
3use axum::response::{IntoResponse, Response};
4use axum::Json;
5
6use crate::payload;
7
8/// Return a JSON error reply with a custom status code.
9pub fn error<T: ToString>(e: T, code: StatusCode) -> Response {
10    (
11        code,
12        Json(payload::ErrorResponse {
13            error: e.to_string(),
14        }),
15    )
16        .into_response()
17}
18
19/// Return a JSON message.
20pub fn message<M: Into<String>>(message: M) -> Response {
21    Json(&payload::MessageResponse::new(message)).into_response()
22}