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

The fetchAPI should return a response no matter what #121

Open
Neraste opened this issue Aug 14, 2021 · 1 comment
Open

The fetchAPI should return a response no matter what #121

Neraste opened this issue Aug 14, 2021 · 1 comment
Labels
refactor Make things more beautiful inside, but same outside

Comments

@Neraste
Copy link
Member

Neraste commented Aug 14, 2021

The fetchAPI middleware returns an object if the payload is of type JSON or nothing otherwise. The response object could be useful to performs some checks programmatically in the reducer, without having to rely on human-readable error details. The middleware should return an object containing the payload or nothing, and the response:

if (contentType !== "application/json") {
  const outcome = {response}
  if (!response.ok) return Promise.reject(outcome)
  return outcome
}

return response.json().then(json => {
  const outcome = {data: json, response}
  if (!response.ok) return Promise.reject(outcome)
  return outcome
}
@Neraste Neraste added the refactor Make things more beautiful inside, but same outside label Jul 28, 2024
@Neraste
Copy link
Member Author

Neraste commented Jul 28, 2024

I think I tried the solution above, but ran into problems quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Make things more beautiful inside, but same outside
Projects
None yet
Development

No branches or pull requests

1 participant