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 394ebc0 commit 7745f65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ 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(json!({ error: "NoSuchService", id: 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
2 changes: 1 addition & 1 deletion src/service_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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, r#"{"error":"NoSuchService","id":"unknown-id"}"#);
}
}

Expand Down

0 comments on commit 7745f65

Please sign in to comment.