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

RelayDefaultNetworkLayer, throw Error also on non-200 response. #1163

Closed

Conversation

Globegitter
Copy link
Contributor

@Globegitter Globegitter commented May 23, 2016

Right now the mutation transacion gets its error attribute set differently on server-side non-200 responses (e.g. 500) compared to 200 responses that include the errors attribute in the json. On the latter it is an Error object as described in the docs but on the first we still get the normal fetch Response. (So https://facebook.github.io/relay/docs/api-reference-relay-store.html#commitupdate-static-method is not completely right)

That also means handling these two different cases in the mutation onFailure call requires two very different pieces of logic.

This PR now makes it so that transaction.getError() always returns an Error, and if it was a non-200 response it also includes that status code.

@ghost ghost added the CLA Signed label May 23, 2016
@@ -2,7 +2,7 @@
parser: babel-eslint

extends:
- ./node_modules/fbjs-scripts/eslint/.eslintrc
- ./node_modules/fbjs-scripts/eslint/.eslintrc.js
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to conflict with #1161

Can you please revert this bit or rebase and then we can import this.

@wincent
Copy link
Contributor

wincent commented May 24, 2016

Thanks @Globegitter. This looks pretty good to me. One comment inline though, otherwise looks good to import.

@Globegitter
Copy link
Contributor Author

@wincent Oh yeah sorry forgot to remove that again. Just rebased.

@steveluscher
Copy link
Contributor

@facebook-github-bot import

@ghost
Copy link

ghost commented May 25, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

networkLayer.sendMutation(request);
expect(fetch).toBeCalled();
const failureResponse = genFailureResponse(response);
expect(failureResponse.status >= 300 || failureResponse.status < 200).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since failureResponse isn't part of the network layer, let's not make assertions about it in the test body.

@steveluscher
Copy link
Contributor

Ping! I left some comments in the code that came up after an internal code review.

@Globegitter
Copy link
Contributor Author

Globegitter commented Jul 7, 2016

@steveluscher sorry about the delay, was a bit busy and then went on holiday (well still am). Just looked over sharing the code and yes we can share some code, but they are also slightly different scenarios (i.e. a non-200 response is might to not return json).

Overall I do think I agree with you though so I'll updating the PR now.

@Globegitter
Copy link
Contributor Author

Globegitter commented Jul 7, 2016

Only typecheck (same as on master) is failing so good to review again @steveluscher

@@ -132,7 +122,7 @@ class RelayDefaultNetworkLayer {
method: 'POST',
};
}
return fetch(this._uri, init).then(throwOnServerError);
return fetch(this._uri, init).then(throwOnServerError.bind(this, request));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why .bind(…)? I couldn't see a reference to this inside that function body.

Copy link
Contributor

Choose a reason for hiding this comment

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

OH. The request argument. I see.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it wasn't a 100% ideal but that seemed to me the best way to share the error creation in all three places (or of course an arrow function if that has any advantages).

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants