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 Mar 1, 2016
1 parent 9f520eb commit f982f0d
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 @@ -93,10 +93,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 @@ -149,7 +149,8 @@ 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\"}");
}

it "should get the appropriate CORS headers" {
Expand Down

0 comments on commit f982f0d

Please sign in to comment.