Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript fetch只抛出TypeError吗_Javascript_Reactjs_Fetch - Fatal编程技术网

Javascript fetch只抛出TypeError吗

Javascript fetch只抛出TypeError吗,javascript,reactjs,fetch,Javascript,Reactjs,Fetch,我可以假设fetch只能抛出类型错误的错误吗 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){

我可以假设fetch只能抛出类型错误的错误吗

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();

fetch
也可以抛出
abortorror
。有关更多详细信息,请参阅