export class PortalMailTemplateError extends Error { constructor( readonly templateName: string, cause: unknown, ) { super(`Mail template rendering failed for "${templateName}": ${errorMessage(cause)}`); this.name = 'PortalMailTemplateError'; this.cause = cause; } } export class PortalMailDeliveryError extends Error { constructor( readonly templateName: string, cause: unknown, ) { super(`Mail delivery failed for "${templateName}": ${errorMessage(cause)}`); this.name = 'PortalMailDeliveryError'; this.cause = cause; } } function errorMessage(error: unknown): string { return error instanceof Error ? error.message : 'unknown error'; }