1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crategen_response;
use ;
use Body as HttpBody;
use Serialize;
const STATUS_FAILED: &'static str = "failed";
/// Generates a failed JSON response with the provided message and status code.
///
/// It generates JSON response in the following JSON format:
///
/// ```json
/// {
/// "status": "failed",
/// "code": "<status_code>",
/// "message": "<error_message>"
/// }
///```
///
/// # Examples
///
/// ```
/// use hyper::{Body, Request, Response, StatusCode};
/// use routerify_json_response::{json_failed_resp_with_message};
///
/// async fn list_books_handler(_: Request<Body>) -> Result<Response<Body>, routerify_json_response::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",
/// )
/// }
/// ```
/// Generates a failed JSON response with the status code specific message and status code.
///
/// It generates JSON response in the following JSON format:
///
/// ```json
/// {
/// "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_json_response::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)
/// }
/// ```