{"action":"closed","issue":{"url":"https://api.github.com/repos/tc39/ecmascript-asyncawait/issues/71","labels_url":"https://api.github.com/repos/tc39/ecmascript-asyncawait/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/tc39/ecmascript-asyncawait/issues/71/comments","events_url":"https://api.github.com/repos/tc39/ecmascript-asyncawait/issues/71/events","html_url":"https://github.com/tc39/ecmascript-asyncawait/issues/71","id":111298530,"number":71,"title":"Code with error handling is still bloated ","user":{"login":"mohsen1","id":543633,"avatar_url":"https://avatars.githubusercontent.com/u/543633?v=3","gravatar_id":"","url":"https://api.github.com/users/mohsen1","html_url":"https://github.com/mohsen1","followers_url":"https://api.github.com/users/mohsen1/followers","following_url":"https://api.github.com/users/mohsen1/following{/other_user}","gists_url":"https://api.github.com/users/mohsen1/gists{/gist_id}","starred_url":"https://api.github.com/users/mohsen1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohsen1/subscriptions","organizations_url":"https://api.github.com/users/mohsen1/orgs","repos_url":"https://api.github.com/users/mohsen1/repos","events_url":"https://api.github.com/users/mohsen1/events{/privacy}","received_events_url":"https://api.github.com/users/mohsen1/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-14T00:28:17Z","updated_at":"2015-10-14T20:26:04Z","closed_at":"2015-10-14T20:26:04Z","body":"Disclaimer: I haven't read the spec fully. I might be wrong about how you *should* handle errors with async/await. Sorry if it's just noise.\r\n\r\nFirst time I saw `async` functions proposal I got really excited and I thought it will make asynchronous code much cleaner. But now that I'm using it I have the impression that it's almost same amount of code but with different keywords and syntax.\r\n\r\nConsider this example using the Fetch API:\r\n\r\n```js\r\nfetch('file.json')\r\n  .then(response => {\r\n    response.json()\r\n    .then(result => {\r\n      console.log('result: ', result);\r\n    })\r\n  })\r\n```\r\nThis can be done with `async/await` much cleaner:\r\n\r\n```js\r\n(async ()=> {\r\n  console.log('result: ', await (await fetch('file.json')).json());\r\n})();\r\n```\r\nNow, if I decide to handle errors for fetch() and json() calls my code becomes a lot more bloated:\r\n\r\n```js\r\n(async ()=> {\r\n  let response = null;\r\n  \r\n  try {\r\n    response = await fetch('file.json');\r\n  } catch (fetchError) {\r\n    console.error(fetchError);\r\n    \r\n    try {\r\n      console.log('result: ', await response.json());\r\n    } catch(jsonParseError) {\r\n      console.error(jsonParseError);\r\n    }\r\n  }\r\n})();\r\n```\r\n\r\nThat is not really less than old way of doing async (with error handling):\r\n\r\n```js\r\nfetch('file.json')\r\n  .then(response => {\r\n    response.json()\r\n    .then(result => {\r\n      console.log('result: ', result);\r\n    })\r\n    .catch(jsonParseError => {\r\n      console.error(jsonParseErorr);\r\n    })\r\n  })\r\n  .catch(fetchError => {\r\n    console.error(fetchError);\r\n  })\r\n```\r\nIn fact I like the the .then()/.catch() better. \r\n\r\nI don't have any proposal for a better syntax but I want to start the conversation about error handling."}}