是否仅提取会引发TypeError

时间:2019-03-05 18:11:45

标签: javascript reactjs fetch

我可以假设提取只能抛出个TypeError错误吗?

const request = async () => {
    let response = null;
    try {
     response = await fetch('https://api.com/values/1');
    } catch (err){
      //is the err here is always of type typeError
    }
    if(!response.ok){
      //bla bla bla 401/403 ...
    }
    const json = await response.json();
    console.log(json);
}

request();

1 个答案:

答案 0 :(得分:1)

fetch也可能抛出AbortError。有关更多详细信息,请参见the documentation