diff --git a/src/functions/error/error.ts b/src/functions/error/error.ts index 6febb50..38d5df2 100644 --- a/src/functions/error/error.ts +++ b/src/functions/error/error.ts @@ -1,9 +1,19 @@ import { COLORS } from "../../constants"; import { colorizeText } from "../../utils/colorizeText"; -export const error = (message: string) => { +export const error = (message: string | Error) => { const label = colorizeText("[ERROR]", COLORS.red); - const messageColorized = colorizeText(message, COLORS.red); - console.error(`${label} ${messageColorized}`); + if (typeof message === "string") { + const messageColorized = colorizeText(message, COLORS.red); + + console.error(`${label} ${messageColorized}`); + } else { + const stack = message.stack?.split("\n").slice(1).join("\n"); + + const messageColorized = colorizeText(message.message, COLORS.red); + const stackColorized = colorizeText(stack, COLORS.dim); + + console.error(`${label} ${messageColorized}\n${stackColorized}`); + } }; diff --git a/src/test.ts b/src/test.ts index 81575de..c57c28b 100644 --- a/src/test.ts +++ b/src/test.ts @@ -4,3 +4,4 @@ kittylog.info("Info..."); kittylog.success("Success..."); kittylog.warning("Warn..."); kittylog.error("Error..."); +kittylog.error(new Error("Error..."));