DakaraProject / dakara-client-web

Web client for the Dakara Project
MIT License
5 stars 1 forks source link

The fetchAPI should return a response no matter what #121

Open Neraste opened 3 years ago

Neraste commented 3 years ago

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 commented 4 months ago

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