21 lines
620 B
TypeScript
21 lines
620 B
TypeScript
export class PublicError extends Error {
|
|
code: string;
|
|
constructor(code: string, message?: string) {
|
|
super(message ?? code);
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
export function publicMessageFor(code: string) {
|
|
// Consumer-safe message - only for sensitive pages like auth
|
|
return "Something went wrong. Please contact the website owner.";
|
|
}
|
|
|
|
export function createValidationError(message: string) {
|
|
return new PublicError("VALIDATION_ERROR", message);
|
|
}
|
|
|
|
export function isPublicError(err: unknown): err is PublicError {
|
|
return typeof err === "object" && err !== null && "code" in err && err instanceof Error;
|
|
}
|