javascript
1fetch('flowers.jpg').then(function(response) { 2 if(response.ok) { 3 return response.blob(); 4 } 5 throw new Error('Network response was not ok.'); 6}).then(function(myBlob) { 7 var objectURL = URL.createObjectURL(myBlob); 8 myImage.src = objectURL; 9}).catch(function(error) { 10 console.log('There has been a problem with your fetch operation: ', error.message); 11});
上記ではresponse.okで成功を判定し、さらにその下でエラー時の処理を記述しています
しかし、最下部でcatch(function(error){...}
という処理も記述されており、これらのエラー処理の違いがわかりません
エラー時の処理は全く同様に見受けられたのですが、何か違いがあるのでしょうか?
たとえば下記のような記述でも処理は同様でしょうか?
javascript
1fetch('flowers.jpg').then(function(response) { 2 return response.blob(); 3}).then(function(myBlob) { 4 var objectURL = URL.createObjectURL(myBlob); 5 myImage.src = objectURL; 6}).catch(function(error) { 7 console.log('There has been a problem with your fetch operation: Network response was not ok.; 8});

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/06/15 19:32 編集
2019/06/15 23:06
退会済みユーザー
2019/06/16 03:22
2019/06/16 03:51