client-blame-error
Version:
Returns funny and diverse error messages subtly suggesting the error is on the user's side. Supports categories and languages.
77 lines (70 loc) • 3.52 kB
JavaScript
// errorMessageLib.js
const messages = {
en: {
technical: [
"Hmm, this might be a you problem. Double-check your payload.",
"Our servers are fine. Are you sure your request isn’t cursed?",
"That didn’t go as planned — for you. Check your input.",
"You broke it. Just kidding… or are we?",
"We're 99% sure it's not our fault. Try again with valid data.",
],
funny: [
"Have you tried turning yourself off and on again?",
"It’s not me, it’s you.",
"Something broke. It might be your vibe.",
"The universe glitched — and you're the glitch.",
"Please consult your nearest tech wizard. Something’s up on your end.",
"Error: Your fingers typed something suspicious.",
"Are you okay? Because your request isn't.",
"Oopsie daisy! Something silly just happened. Maybe check your stuff?",
"Your request tripped over a wire. Again.",
"That request looked weird. Did your cat walk on the keyboard?",
],
sarcastic: [
"We tried blaming ourselves, but nope — still your fault.",
"Our code's feelings are hurt. What did you send it?",
"This error smells like user input.",
"Whatever you did, don't do that again.",
"Nice try. But… no.",
"The error gods are angry — and you’re the reason.",
"Well, well, well… look who made a boo-boo.",
],
random: [
"If errors were currency, you'd be rich!",
"This request brought chaos. Are you a Slytherin by chance?",
"Congratulations! You've triggered a rare client-side anomaly.",
"This is why we can’t have nice things.",
"According to our calculations… it’s your fault.",
],
},
hi: {
funny: [
"अरे बाप रे! कुछ तो गड़बड़ है — शायद तुम्हारी तरफ से।",
"गलती तेरी थी, दिल से माफ किया।",
"तू फिर से क्या लेकर आया ये?",
],
technical: [
"लगता है डेटा में कुछ समस्या है। एक बार फिर से जाँच कर लें।",
"हमारी सर्वर तो बढ़िया है, आप अपने इनपुट देखो।",
],
sarcastic: [
"लगता है तुम फिर से कुछ गलत कर बैठे।",
"आपका अनुरोध देखने के बाद सर्वर ने resignation दे दिया।",
],
random: [
"तुम्हारे कारण ब्रह्मांड में एक एरर हो गया।",
],
},
};
function getRandomErrorMessage({ language = "en", category = null } = {}) {
const langMessages = messages[language] || messages.en;
let selectedCategory = category;
if (!selectedCategory || !langMessages[selectedCategory]) {
const categories = Object.keys(langMessages);
selectedCategory = categories[Math.floor(Math.random() * categories.length)];
}
const categoryMessages = langMessages[selectedCategory];
const randomIndex = Math.floor(Math.random() * categoryMessages.length);
return categoryMessages[randomIndex];
}
module.exports = { getRandomErrorMessage };