- 574 名前:534 mailto:sage [2016/06/11(土) 16:40:58.22 ID:ijG8u0pc.net]
- >>544 の綺麗なコードを見る前に、API問い合わせの部分を関数に分離しようと思って、fetch用の追加のエラーハンドリングも加えてこう書いてしまったんですね(お蔵入りですが、このなかで疑問が沸いたので・・)
function googleCustomSearch(query) { return fetch(window.googleCustomSearchApi + query) .then(handleNetworkError) .then(response => response.json()) .then(json => { chrome.storage.local.set({[query]: json}); return json; }) .catch(err => { // 【ここが疑問】 }); } function handleNetworkError(response) { if (!response.ok) { throw new Error(reponse.status, response.statusText); } return response; }
|

|