Initial commit
This commit is contained in:
20
lib/errors.ts
Normal file
20
lib/errors.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user