Last active
April 18, 2018 06:53
-
-
Save yonjah/8b599a13f8c7555b0ae6ac6ec1ae3dd9 to your computer and use it in GitHub Desktop.
Comment for https://medium.com/@sebelga/simplify-your-code-adding-hooks-to-your-promises-9e1483662dfa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function chargeCreate ({ amount, source, description, currency }) { | |
//do some stuff before the function | |
await someService.doAsyncStuff(amount, currency, description); | |
try { | |
const charge = await stripe.charges.create.apply(stripe.charges, arguments); | |
//do some stuff after the function | |
myTraceService.log(`New charge ${charge.amount}`); | |
return charge; | |
} catch (e) { | |
// do something with the error if you want to | |
throw e; | |
} | |
} | |
// No changes on the processPayement | |
async function processPayement (amount, source, description) { | |
let charge; | |
try { | |
charge = await chargeCreate({ | |
amount, | |
source, | |
description, | |
currency: "usd" | |
}); | |
} catch (e) { | |
// Error handling | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment