From 201b08a43aace1530ac4af55ffe3841500c79acf Mon Sep 17 00:00:00 2001 From: dm1981 Date: Fri, 12 Mar 2021 17:09:19 -0300 Subject: [PATCH] Remove non-reacheable code after a 'throw' clause --- .../asynchronous/async_await/index.html | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/files/en-us/learn/javascript/asynchronous/async_await/index.html b/files/en-us/learn/javascript/asynchronous/async_await/index.html index 4347bf2e74d9acf..218f2d96362ef2f 100644 --- a/files/en-us/learn/javascript/asynchronous/async_await/index.html +++ b/files/en-us/learn/javascript/asynchronous/async_await/index.html @@ -102,9 +102,8 @@

Rewriting promise code with asyn .then(response => {   if (!response.ok) {     throw new Error(`HTTP error! status: ${response.status}`); -  } else { -    return response.blob(); -  } +  } +  return response.blob(); }) .then(myBlob => { let objectURL = URL.createObjectURL(myBlob); @@ -123,13 +122,14 @@

Rewriting promise code with asyn if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); - } else { - let myBlob = await response.blob(); + } + + let myBlob = await response.blob(); - let objectURL = URL.createObjectURL(myBlob); - let image = document.createElement('img'); - image.src = objectURL; - document.body.appendChild(image); + let objectURL = URL.createObjectURL(myBlob); + let image = document.createElement('img'); + image.src = objectURL; + document.body.appendChild(image); } } @@ -146,9 +146,9 @@

Rewriting promise code with asyn let response = await fetch('coffee.jpg'); if (!response.ok) {     throw new Error(`HTTP error! status: ${response.status}`); -  } else { -    return await response.blob(); -  } +  } +  return await response.blob(); + } myFetch().then((blob) => { @@ -188,13 +188,13 @@

Adding error handling

if (!response.ok) {   throw new Error(`HTTP error! status: ${response.status}`); - } else { -  let myBlob = await response.blob(); -  let objectURL = URL.createObjectURL(myBlob); -  let image = document.createElement('img'); -  image.src = objectURL; -  document.body.appendChild(image); - } + } +  let myBlob = await response.blob(); +  let objectURL = URL.createObjectURL(myBlob); +  let image = document.createElement('img'); +  image.src = objectURL; +  document.body.appendChild(image); + } catch(e) { console.log(e); } @@ -210,9 +210,9 @@

Adding error handling

let response = await fetch('coffee.jpg'); if (!response.ok) {   throw new Error(`HTTP error! status: ${response.status}`); - } else { -  return await response.blob(); } +  return await response.blob(); + } myFetch().then((blob) => { @@ -247,15 +247,15 @@

Awaiting a Promise.all()

if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); - } else { - if(type === 'blob') { - content = await response.blob(); - } else if(type === 'text') { - content = await response.text(); - } - - return content; } + if(type === 'blob') { + content = await response.blob(); + } else if(type === 'text') { + content = await response.text(); + } + + return content; + }