Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 10, 2025 10:30
Show Gist options
  • Save mcsee/f013d66121679aa736daa7900d3f3f40 to your computer and use it in GitHub Desktop.
Save mcsee/f013d66121679aa736daa7900d3f3f40 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
function processPayment(paymentData) {
try {
// Too broad try catch
validatePayment(paymentData);
chargeCard(paymentData);
sendConfirmation(paymentData.email);
} catch (error) {
// Generic error message shown to user
return {
success: false,
userMessage: "Oops! Something went wrong. Please try again.",
error: error.message
};
}
}
function handleError(res, error) {
// Exposing HTTP 500 to users
res.status(500).json({
message: "Internal Server Error",
error: error.message
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment