[whatwg/fetch] fetch() doesn't properly handle errors from pre-flight responses with CORS (#443)

I've opened this issues because I'm suprised to not see another one open/closed. Maybe I missed it.

I really don't understand how people are creating production-quality applications with `fetch()` as it does not give access to pre-flight responses.

When an application throws a 403 for example. How is that supposed to be handled with `fetch()`? The only information we have access to is the error form `fetch()` which doesn't even contain a status code. All it contains is the generic string `TypeError: Failed to fetch`

How do we know the difference between a 401? a 403? a 502? a 500? 

Sorry for the dramatic example below but this is really frustrating:

```
function handleErrors(response) {
    if (!response.ok) {
        console.log(response)
    }
    return response;
}

fetch("http://httpstat.us/403")
    .then(handleErrors)
    .then(function(response) {
        console.log("ok");
    }).catch(function(error) {
        console.log('there was an error');
        console.log('but I don\'t have access to the status code');
        console.log('So how can my application know what to do?');
        console.log('Should I send the HTTP request again?');
        console.log('Maybe my cookie is expired so I need to log in?');
        console.log('Why don\'t I have access to response.statusCode?');
        console.log(error);
    });
```

Is whatwg expecting all applications to send back a 200 for every pre-flight CORS request? 







-- 
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/443

Received on Thursday, 22 December 2016 22:27:43 UTC