From 761fe191b020061f4f15aa580ba7da752d646f0e Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 4 Sep 2018 14:21:20 +0200 Subject: [PATCH] Use ES6 async/await in the example Hi, I'm a beginner developer. I think now it's more clear with ES6 Async/await and arrow function. I didn't use try-catch because throw. I'm just practising! Any suggestion is very welcome --- sections/errorhandling/useonlythebuiltinerror.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sections/errorhandling/useonlythebuiltinerror.md b/sections/errorhandling/useonlythebuiltinerror.md index 794ceb6b..e53de0fe 100644 --- a/sections/errorhandling/useonlythebuiltinerror.md +++ b/sections/errorhandling/useonlythebuiltinerror.md @@ -16,12 +16,11 @@ const myEmitter = new MyEmitter(); myEmitter.emit('error', new Error('whoops!')); // 'throwing' an Error from a Promise -return new Promise(function (resolve, reject) { - return DAL.getProduct(productToAdd.id).then((existingProduct) => { - if(existingProduct != null) - reject(new Error("Why fooling us and trying to add an existing product?")); - }); -}); +const addProduct = async (productToAdd) => { + const existingProduct = await DAL.getProduct(productToAdd.id); + if (existingProduct != null) + reject(new Error("Why fooling us and trying to add an existing product?")); +} ``` ### Code example – Anti Pattern