Skip to content

Commit

Permalink
Use ES6 async/await in the example
Browse files Browse the repository at this point in the history
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
  • Loading branch information
imsergiobernal authored Sep 4, 2018
1 parent 917b32d commit 761fe19
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions sections/errorhandling/useonlythebuiltinerror.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 761fe19

Please sign in to comment.