Skip to content

Commit

Permalink
Switching service error response to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Christiane Ruetten committed Feb 26, 2016
1 parent 7fc512c commit 1bc46a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ impl Controller for FoxBox {
let services = self.services.lock().unwrap();
match services.get(&id) {
None => {
let mut response = Response::with(format!("No Such Service: {}", id));
let mut response = Response::with(format!(
"{{\"result\": \"error\", \"details\": \"No Such Service: {}\"}}", id));
response.status = Some(Status::BadRequest);
response.headers.set(AccessControlAllowOrigin::Any);
response.headers.set(ContentType::plaintext());
response.headers.set(ContentType::json());
Ok(response)
}
Some(service) => {
Expand Down
3 changes: 2 additions & 1 deletion src/service_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe! service_router {
&service_router).unwrap();

let result = response::extract_body_to_string(response);
assert_eq!(result, "No Such Service: unknown-id");
assert_eq!(result,
"{\"result\": \"error\", \"details\": \"No Such Service: unknown-id\"}");
}
}

0 comments on commit 1bc46a8

Please sign in to comment.