Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching service error response to JSON #92

Merged
merged 1 commit into from
Mar 3, 2016
Merged

Conversation

cr
Copy link
Contributor

@cr cr commented Feb 26, 2016

Seems wrong to deliver plaintext errors there.

@cr cr force-pushed the cr-service-error branch from a263229 to 1bc46a8 Compare February 26, 2016 20:17
@@ -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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to the new json macros, and do something like : { error: "NoSuchService", id: id }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ferjm
Copy link
Member

ferjm commented Feb 29, 2016

FWIW we are using this response format for the user related endpoints https://github.com/fxbox/users/blob/master/doc/API.md#response-format

@cr cr force-pushed the cr-service-error branch from 1bc46a8 to b9b11e4 Compare February 29, 2016 14:02
@cr
Copy link
Contributor Author

cr commented Feb 29, 2016

@ferjm, that error spec is a great goal aim for. I'd prefer to be switching to your format in all the places at once in a separate PR, coordinating with gmarty who is already consuming API errors.

@cr cr force-pushed the cr-service-error branch from b9b11e4 to 1987539 Compare February 29, 2016 14:11
@fabricedesre
Copy link
Collaborator

The fxbox/users repo uses numeric error codes. That's fine when you just mirror the http ones, but please don't add new custom ones. Instead, use strings like most DOM apis do, that's much more understandable.

@cr
Copy link
Contributor Author

cr commented Mar 1, 2016

So are we going to land this?

@fabricedesre
Copy link
Collaborator

This needs to be rebased

@cr cr force-pushed the cr-service-error branch 2 times, most recently from b83d7bb to 70b0fa7 Compare March 1, 2016 16:21
@cr
Copy link
Contributor Author

cr commented Mar 1, 2016

Looks like a few json! switches were already landed in other patches.

@@ -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, "{\"error\":\"NoSuchService\",\"id\":\"unknown-id\"}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a nicer string litteral syntax: r#{"error": "NoSuchService" ... }#

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work in this context:

error: found invalid character; only `#` is allowed in raw string delimitation: {
           assert_eq!(result, r#{"error":"NoSuchService","id":"unknown-id"}#);
                          ^~

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also fixed the indent.

@fabricedesre
Copy link
Collaborator

Also, please squash your commits

@cr cr force-pushed the cr-service-error branch from 70b0fa7 to 7745f65 Compare March 1, 2016 18:08
@cr
Copy link
Contributor Author

cr commented Mar 2, 2016

Ok, @fabricedesre ?

@cr cr force-pushed the cr-service-error branch from 7745f65 to 6603e99 Compare March 3, 2016 16:11
fabricedesre added a commit that referenced this pull request Mar 3, 2016
Switching service error response to JSON
@fabricedesre fabricedesre merged commit cf498e6 into master Mar 3, 2016
@cr cr deleted the cr-service-error branch March 3, 2016 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants