const createError = (name: string, statusCode: number, defaultMessage: string) => { return class extends Error { readonly statusCode = statusCode; readonly code = name; constructor(message = defaultMessage) { super(message); this.name = name; Object.setPrototypeOf(this, new.target.prototype); } }; }; export const UserNotFoundError = createError("UserNotFoundError", 404, "User was not found."); export const PostNotFoundError = createError("PostNotFoundError", 404, "Post was not found."); export const BlogNotFoundError = createError("BlogNotFoundError", 404, "Blog was not found."); export const UserEmailExistsError = createError("UserEmailExistsError", 409, "There already is a user with that email."); export const InvalidPasswordError = createError("InvalidPasswordError", 401, "Incorrect password."); export const InvalidLoginError = createError("InvalidLoginError", 401, "User does not exist or password is incorrect."); export const UnauthorizedError = createError("UnauthorizedError", 401, "Unauthorized."); export const ForbiddenError = createError("ForbiddenError", 403, "Forbidden."); export const SubdomainAlreadyUsedError = createError("SubdomainAlreadyUsedError", 409, "There's already someone using that subdomain."); export const InvalidSessionError = createError("InvalidSessionError", 401, "Session invalid or expired.");