Skip to content

Commit

Permalink
Merge pull request #8 from vclemenzi/master
Browse files Browse the repository at this point in the history
feat(error): `Error` class support
  • Loading branch information
pietrodev07 authored Jan 20, 2024
2 parents f987cf2 + 92c0b6d commit 7209c6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/functions/error/error.ts
Original file line number Diff line number Diff line change
@@ -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}`);
}
};
1 change: 1 addition & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ kittylog.info("Info...");
kittylog.success("Success...");
kittylog.warning("Warn...");
kittylog.error("Error...");
kittylog.error(new Error("Error..."));

0 comments on commit 7209c6d

Please sign in to comment.