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

handleResponse on the adapter is never called when using fetch and a response with no body #6851

Closed
kategengler opened this issue Dec 4, 2019 · 8 comments
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@kategengler
Copy link
Member

When using fetch, a response with a status and an empty body never hits handleResponse on the application adapter.

If I turn jquery-integration back on, such that useFetch is true, then handleResponse is hit, for the same response code and empty body.

Jumping through the debugger, I can follow it down to response.text() in determineBodyPromise, but it never makes it to the then on that promise. It seems like there may be a missing catch in the chain of promises here https://github.com/emberjs/data/blob/master/packages/adapter/addon/rest.js#L1002

Versions

Run the following command and paste the output below: yarn list ember-source && yarn list ember-cli && yarn list --pattern ember-data.

└─ [email protected]

└─ [email protected]

├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
└─ [email protected]
@runspired
Copy link
Contributor

I think there's three changes to make and add test coverage for here:

  • we need to catch and handle if determineBodyPromise errors
  • we need to make sure if fetch itself rejects we still catch that and process correctly
  • we should fix determineBodyPromise's ability to handle empty payloads

@Gaurav0 mind taking a look?

@andreyfel
Copy link
Contributor

I think I encountered a similar issue. When my server returns 401 with an empty body I'm getting "SyntaxError: Unexpected end of JSON input" in the application route error action instead of the 401 error.
It started happening in Ember Data 3.14. It worked as expected in ED 3.13.

A change in this file caused the issue:
packages/adapter/addon/-private/utils/determine-body-promise.ts
#6293

There is a new throw that breaks the chain. Interesting that the throw happens only in if (DEBUG) check. So, in the production build the behavior would be different.

@kategengler
Copy link
Member Author

@andreyfel I think that you may be seeing the same bug, but I don't think the PR you linked to is the cause: In my testing, it never made it into the then on response.text() in that method, so it would never reach the code that was added.

@andreyfel
Copy link
Contributor

@kategengler In my case I've set a breakpoint on the code I was talking about and I could see that it was reached.

@kategengler
Copy link
Member Author

@andreyfel It may be a different bug then, as I did the same for just inside the then on response.text() and the breakpoint was never hit.

@andreyfel
Copy link
Contributor

@kategengler can you check if your issue can be reproduced with ED 3.13?

@runspired
Copy link
Contributor

This should be resolved by #6871

@runspired
Copy link
Contributor

Fix can be tested with 3.16.0-alpha.3

@runspired runspired added 🏷️ bug This PR primarily fixes a reported issue and removed Bug labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

No branches or pull requests

3 participants