-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (34 loc) · 1 KB
/
Copy pathindex.js
File metadata and controls
39 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// fake-error-generator/index.js
const types = ["log", "warn", "error", "info"];
function fakeError({
message = "Something went wrong!",
type = "error",
count = 1,
delay = 0
} = {}) {
if (!types.includes(type)) type = "error";
for (let i = 0; i < count; i++) {
setTimeout(() => {
if (type === "log") console.log(`✅ ${message}`);
if (type === "warn") console.warn(`⚠️ ${message}`);
if (type === "error") console.error(`❌ ${message}`);
if (type === "info") console.info(`ℹ️ ${message}`);
}, delay * i);
}
}
// Generate random fake errors
function randomFakeError({
messages = ["Oops!", "Unexpected error!", "Failed to load data!"],
count = 1,
delay = 0
} = {}) {
for (let i = 0; i < count; i++) {
const msg = messages[Math.floor(Math.random() * messages.length)];
const type = types[Math.floor(Math.random() * types.length)];
fakeError({ message: msg, type, count: 1, delay: delay * i });
}
}
module.exports = {
fakeError,
randomFakeError
};