pub fn json_failed_resp_with_message<B, M>(
code: StatusCode,
message: M,
) -> Result<Response<B>>Expand description
Generates a failed JSON response with the provided message and status code.
It generates JSON response in the following JSON format:
{
"status": "failed",
"code": "<status_code>",
"message": "<error_message>"
}ยงExamples
use hyper::{Body, Request, Response, StatusCode};
use json_response::{json_failed_resp_with_message};
async fn list_books_handler(_: Request<Body>) -> Result<Response<Body>, routerify::Error> {
// Generate a failed JSON response in the following format:
// { "status": "failed", code: 500, data: "Internal Server Error: Couldn't fetch book list from database" }
json_failed_resp_with_message(
StatusCode::INTERNAL_SERVER_ERROR,
"Couldn't fetch book list from database",
)
}