Skip to content

Commit da37e26

Browse files
committed
errors::json: Use json! macro to simplify JSON serialization code
1 parent f8ab731 commit da37e26

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/util/errors/json.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ use conduit::{header, StatusCode};
88

99
/// Generates a response with the provided status and description as JSON
1010
fn json_error(detail: &str, status: StatusCode) -> AppResponse {
11-
#[derive(Serialize)]
12-
struct StringError<'a> {
13-
detail: &'a str,
14-
}
15-
#[derive(Serialize)]
16-
struct Bad<'a> {
17-
errors: [StringError<'a>; 1],
18-
}
11+
let json = json!({ "errors": [{ "detail": detail }] });
1912

20-
let mut response = json_response(&Bad {
21-
errors: [StringError { detail }],
22-
});
13+
let mut response = json_response(&json);
2314
*response.status_mut() = status;
2415
response
2516
}

0 commit comments

Comments
 (0)