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

Reversing API status code #962

Conversation

WhoSoup
Copy link
Member

@WhoSoup WhoSoup commented Feb 4, 2020

This is a compatibility issue that came to light in testing 6.5.1. PR #897 changed the API to return status code 200 for json-rpc errors, but the factom.js client relies on status codes to determine whether or not a request is an error. Functionality is being changed back to preserve backward compatibility.

Reversing this means the FAT/factom client is no longer fully compatible due to AdamSLevy/jsonrpc2#3. However, this is a fairly benign issue that results in FAT/factom to return a json-parsing error rather than an appropriate error.

@PaulBernier
Copy link
Contributor

Just for a bit more context: factom.js is breaking indirectly because the http client it uses, axios, handle non 2xx response as rejected Promises, which goes to a different path (catch instead of then), which is a reasonable behavior I think, so any http client having similar handling strategy could also break. The potential for unanticipated breaking goes beyond just factom.js users I think.

@carryforward
Copy link
Contributor

ok, this is being tracked with ticket FD-1281

@carryforward carryforward changed the base branch from master to FD-1281_revert_http_error_codes February 4, 2020 23:07
@carryforward carryforward merged commit 3e1691b into FactomProject:FD-1281_revert_http_error_codes Feb 4, 2020
@AdamSLevy
Copy link
Contributor

factom.js is breaking indirectly because the http client it uses, axios, handle non 2xx response as rejected Promises, which goes to a different path (catch instead of then), which is a reasonable behavior I think, so any http client having similar handling strategy could also break.

Correct me if I'm wrong but it seems like factom.js is misusing the catch path to identify RPC errors. Is axiom also providing the JSON RPC 2.0 parsing? How does the HTTP library matter w.r.t the JSON RPC protocol as used by factom.js?

@AdamSLevy
Copy link
Contributor

I would love to see this get merged back, and factom.js be fixed. The FAT/factom package, and fatd that uses it, depends on distinguishing between a network error and a bad lookup. In some cases both errors are treated as fatal, but when it comes to checking to see if an identity is yet populated, the distinction becomes important.

@WhoSoup
Copy link
Member Author

WhoSoup commented Feb 13, 2020

I would love to see this get merged back, and factom.js be fixed.

It seems at this point, we just don't know how many projects rely on factom.js and/or the api status code, so changing it for V2 is unlikely as it would break too many existing projects. This is something now slated for a V3 api, I believe.

@PaulBernier
Copy link
Contributor

Axios (which for context is one of the most popular HTTP client with 7M weekly downloads) has made the design choice to "route" separately 2xx HTTP response from others. Axios is not aware of RPC, it's just a HTTP client. So as a client I have to use their interface and because factomd returns 4xx response for an error, I have no choice but to handle that in the catch, not up to me to decide. Which is my core point, factomd made a mistake in their RPC2 implementation and clients had no choice but to adapt to this mistake. Of course I totally wish it'd be fixed, but that's just not possible in a backward compatible way. It shows up as a problem in factom.js but could break any other client that worked around factomd current peculiarities...

I have no problem tweaking factom.js to handle both cases and publish a new version, but that would still not make me approve this change implemented this way because of the unknown/unbounded risk of breakage across the entire ecosystem. The correct way to handle this non-backward compatible change is to bump the API version.

@AdamSLevy
Copy link
Contributor

AdamSLevy commented Feb 13, 2020 via email

@AdamSLevy
Copy link
Contributor

I fixed my jsonrpc2 so that it is not so rigid in enforcing http status codes and always tries to unmarshal the response body. So this won't be an issue for my factom library soon.

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.

4 participants