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

Chainable promise state propagation #10

Closed
h2non opened this issue Oct 28, 2014 · 0 comments
Closed

Chainable promise state propagation #10

h2non opened this issue Oct 28, 2014 · 0 comments
Assignees

Comments

@h2non
Copy link
Owner

h2non commented Oct 28, 2014

function status(response) {
  if (response.status >= 200 && response.status < 300) {
    return Promise.resolve(response)
  } else {
    return Promise.reject(new Error(response.statusText))
  }
}

function json(response) {
  return response.json()
}

fetch('/users')
  .then(status)
  .then(json)
  .then(function(json) {
    console.log('request succeeded with json response', json)
  }).catch(function(error) {
    console.log('request failed', error)
  })
@h2non h2non self-assigned this Oct 28, 2014
@h2non h2non changed the title Chainable promises state propagation to pending callbacks Chainable promise state propagation Dec 8, 2014
@h2non h2non closed this as completed Jul 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant