Skip to content

The fetchAPI should return a response no matter what #121

@Neraste

Description

@Neraste

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorMake things more beautiful inside, but same outside

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions