pub fn json_failed_resp<B>(code: StatusCode) -> Result<Response<B>>
Expand description
Generates a failed JSON response with the status code specific message and status code.
It generates JSON response in the following JSON format:
{
"status": "failed",
"code": "<status_code>",
"message": "<status_code_message>"
}
ยงExamples
use hyper::{Body, Request, Response, StatusCode};
use json_response::{json_failed_resp};
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" }
json_failed_resp(StatusCode::INTERNAL_SERVER_ERROR)
}