[−][src]Function routerify_json_response::json_failed_resp
pub fn json_failed_resp<B>(code: StatusCode) -> Result<Response<B>> where
B: HttpBody + From<Vec<u8>> + Send + Sync + Unpin + 'static,
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 routerify_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) }