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

make afterware errors bubble up #982

Merged
merged 5 commits into from
Dec 6, 2016

Conversation

edvinerikson
Copy link
Contributor

@edvinerikson edvinerikson commented Dec 2, 2016

This makes errors thrown from afterwares bubble up so that apollo don't try to parse bad responses.

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change
  • Add your name and email to the AUTHORS file (optional)
  • If this was a change that affects the external API, update the docs and post a link to the PR in the discussion

@edvinerikson edvinerikson force-pushed the dont-silent-afterware branch 3 times, most recently from 956df32 to 8779f20 Compare December 2, 2016 13:37
@helfer
Copy link
Contributor

helfer commented Dec 2, 2016

@edvinerikson Thanks for the PR! Can you explain what problem this solves and add a test case if applicable? Right now it doesn't look like your PR would change any behavior.

@stubailo
Copy link
Contributor

stubailo commented Dec 2, 2016

Looks like the change makes it so that the promise returns the return value of the afterware. However this should definitely come with a test that ensures the behavior continues to work, especially since it's so easy to miss.

@edvinerikson
Copy link
Contributor Author

edvinerikson commented Dec 2, 2016 via email

@edvinerikson
Copy link
Contributor Author

@helfer the reason for the change is because I have a afterware which I check the response status and decide if Apollo will be able to parse the response. in some cases Apollo won't be able to do that and when that happens I throw a error which I can catch in my error handling but without this change I am not able to catch the error and instead Apollo will fail with when trying to parse the json body.

e.g getDataFromTree(app).catch(error => doSomethingWithErrorHere()) but currently the error I get there will be something like unexpected token < at 1:1 (due to a html response) instead of my own error.

@edvinerikson
Copy link
Contributor Author

edvinerikson commented Dec 3, 2016

maybe a improvement to the network layer would be to check response.ok before trying to parse / handle the response as well. will probably help fix some of the cryptic error messages that I get sometimes.

currently I do this in my afterware

@helfer
Copy link
Contributor

helfer commented Dec 5, 2016

@edvinerikson Okay. Please add a test, and then we can merge it.

I think checking response.ok won't work, because some people return error codes that are not in the 200 range for responses that should be parsed and processed. It's unfortunate, but I think we have to live with that for now.

@edvinerikson
Copy link
Contributor Author

I think checking response.ok won't work, because some people return error codes that are not in the 200 range for responses that should be parsed and processed. It's unfortunate, but I think we have to live with that for now.

Yeah I will create my own network layer to handle my cases instead.
Still gonna try to add a test and get this merged.

@edvinerikson
Copy link
Contributor Author

test is added

@edvinerikson edvinerikson force-pushed the dont-silent-afterware branch from 8779f20 to 0a898f9 Compare December 5, 2016 11:44
@helfer
Copy link
Contributor

helfer commented Dec 6, 2016

Sweet, thanks a lot!

@helfer helfer merged commit 7b0e471 into apollographql:master Dec 6, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants