Skip to content

Instantly share code, notes, and snippets.

@yonjah
Last active April 18, 2018 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonjah/8b599a13f8c7555b0ae6ac6ec1ae3dd9 to your computer and use it in GitHub Desktop.
Save yonjah/8b599a13f8c7555b0ae6ac6ec1ae3dd9 to your computer and use it in GitHub Desktop.
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