2025-12-04 23:04:20 +00:00
|
|
|
import { Environment } from "Enums/Environment";
|
|
|
|
|
|
2025-11-17 19:02:15 +00:00
|
|
|
export abstract class Exception {
|
|
|
|
|
|
|
|
|
|
public static throw(error: unknown): never {
|
|
|
|
|
this.log(error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static new(error: unknown): Error {
|
|
|
|
|
return error instanceof Error ? error : new Error(this.messageFrom(error));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static log(error: unknown) {
|
2025-12-04 23:04:20 +00:00
|
|
|
if (process.env.NODE_ENV === Environment.DEV) {
|
2025-11-17 19:02:15 +00:00
|
|
|
const e: Error = this.new(error);
|
|
|
|
|
console.error(e.message, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 12:30:51 +00:00
|
|
|
public static warn(error: unknown) {
|
|
|
|
|
if (process.env.NODE_ENV === Environment.DEV) {
|
|
|
|
|
const e: Error = this.new(error);
|
|
|
|
|
console.warn(e.message, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-17 19:02:15 +00:00
|
|
|
public static messageFrom(error: unknown): string {
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
|
return error.message;
|
|
|
|
|
}
|
|
|
|
|
if (typeof error === "string") {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
if (error && typeof error === "object" && "message" in error) {
|
|
|
|
|
return String(error.message);
|
|
|
|
|
}
|
|
|
|
|
return String(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|