fetch resolves even if 404?

前端 未结 4 631
走了就别回头了
走了就别回头了 2020-11-27 07:22

Using this code :

fetch(\'notExists\') // <---- notice 
    .then(
        function(response)
        {
           alert(response.status)
        }
    )         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 07:53

    Reject handler is for networking and CORS errors iirc. If the request reaches the server and it responds with a valid http response, the promise gets fulfilled, even if the response is of code 4xx or 5xx.

提交回复
热议问题