Last active
August 10, 2025 10:30
-
-
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
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
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