mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Add Exception helper class for consistent error handling and logging. Replace throw statements and console.error calls with Exception methods. Update service methods to return Error | T instead of mixed success/failure objects. Improve type safety in Claude.extractContents with explicit return type. Add WikiLinks helper to VaultCacheService for managing wiki link references. Update unit tests.
32 lines
No EOL
849 B
TypeScript
32 lines
No EOL
849 B
TypeScript
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) {
|
|
if (process.env.NODE_ENV !== "production") {
|
|
const e: Error = this.new(error);
|
|
console.error(e.message, e);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
} |