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

how to send a PATCH request? #123

Closed
ycdesu opened this issue Feb 11, 2015 · 3 comments · Fixed by #124
Closed

how to send a PATCH request? #123

ycdesu opened this issue Feb 11, 2015 · 3 comments · Fixed by #124

Comments

@ycdesu
Copy link

ycdesu commented Feb 11, 2015

hello, I read http.js and found that it doesn't support PATCH method. I try to call this.request with option {method: "patch" ...} to send a PATCH request. The problem is, I don't know how to handle the promise rejection if an error occurred. Could you tell me where can I get enough information to achieve this? thanks.

@oliverwoodings
Copy link
Contributor

Hi @ycavatars, the HttpStateSource uses the isomorphic-fetch polyfill for making the request. When you make a call to this.request it calls the fetch API and then handles the response for you (see code here). If the server responds with status 400 or greater, Marty will throw the response as an exception. Otherwise it will resolve normally. Therefore you can do the following:

this.request({ method: "patch" ...})
  .then(function (res) {
    console.log("everything went better than expected!");
  })
  .catch(function (res) {
    console.log("something foobar'd");
  });

Does that help?

@ycdesu
Copy link
Author

ycdesu commented Feb 11, 2015

yes, really thanks :)

@oliverwoodings
Copy link
Contributor

I'll do a quick PR for you to add in the PATCH method as a sugar function like the other methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants