- From: Tejas Kumar <notifications@github.com>
- Date: Tue, 07 Nov 2017 10:57:03 +0000 (UTC)
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/627@github.com>
## The Issue I find working with this API fairly different to reason about when calling `fetch` and receiving an error response from an external resource. Currently, I am implementing a feature that has the following flow: - `fetch` a resource with `GET` - if said resource doesn't yet exist, do a new `fetch` call with `POST` - continue doing things. Currently, if the GET fails with a `404`, the promise is _not rejected_ and I am unable to handle the error appropriately (by creating what does not already exist). ## Proposed Change The API that I (and others on my team) imagine and would typically expect to work with is as follows: ```js const getMyThing = () => { // Try to GET it. fetch("https://myendpoint.com/myThing/thingName") // resolves! Awesome, let's process it. .then(thing => thing.process()) /* Error? It would be nice if the rejection contained the Response, with headers and status code. */ .catch(error => { if (error.status === 404) { // create it and return its promise. return createMyThing("thingName") } // throw the error. throw new Error(error) }) } ``` If this issue makes sense and is considered, I'm happy to help describe, implement or test to the best of my ability. cc @Angarsk8 as a fellow coder with this issue. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/627
Received on Tuesday, 7 November 2017 10:57:30 UTC