|
| 1 | +/** |
| 2 | + * @gello/mail-core - Error Types |
| 3 | + * |
| 4 | + * Tagged error types for the mail system. |
| 5 | + */ |
| 6 | + |
| 7 | +import { Data } from "effect" |
| 8 | +import type { MessageId } from "./types.js" |
| 9 | + |
| 10 | +/** |
| 11 | + * Base mail error |
| 12 | + */ |
| 13 | +export class MailError extends Data.TaggedError("MailError")<{ |
| 14 | + readonly message: string |
| 15 | + readonly cause?: unknown |
| 16 | +}> {} |
| 17 | + |
| 18 | +/** |
| 19 | + * Connection error to mail provider |
| 20 | + */ |
| 21 | +export class MailConnectionError extends Data.TaggedError("MailConnectionError")<{ |
| 22 | + readonly message: string |
| 23 | + readonly provider: string |
| 24 | + readonly cause?: unknown |
| 25 | +}> {} |
| 26 | + |
| 27 | +/** |
| 28 | + * Email validation error (invalid address, missing fields, etc.) |
| 29 | + */ |
| 30 | +export class MailValidationError extends Data.TaggedError("MailValidationError")<{ |
| 31 | + readonly message: string |
| 32 | + readonly field: string |
| 33 | + readonly value?: unknown |
| 34 | +}> {} |
| 35 | + |
| 36 | +/** |
| 37 | + * Delivery error from provider |
| 38 | + */ |
| 39 | +export class MailDeliveryError extends Data.TaggedError("MailDeliveryError")<{ |
| 40 | + readonly message: string |
| 41 | + readonly messageId: MessageId |
| 42 | + readonly provider: string |
| 43 | + readonly providerError?: string |
| 44 | + readonly statusCode?: number |
| 45 | +}> {} |
| 46 | + |
| 47 | +/** |
| 48 | + * Template rendering error |
| 49 | + */ |
| 50 | +export class TemplateError extends Data.TaggedError("TemplateError")<{ |
| 51 | + readonly message: string |
| 52 | + readonly template?: string |
| 53 | + readonly cause?: unknown |
| 54 | +}> {} |
| 55 | + |
| 56 | +/** |
| 57 | + * Template not found error |
| 58 | + */ |
| 59 | +export class TemplateNotFoundError extends Data.TaggedError("TemplateNotFoundError")<{ |
| 60 | + readonly message: string |
| 61 | + readonly template: string |
| 62 | +}> {} |
| 63 | + |
| 64 | +/** |
| 65 | + * Attachment error (file not found, too large, etc.) |
| 66 | + */ |
| 67 | +export class AttachmentError extends Data.TaggedError("AttachmentError")<{ |
| 68 | + readonly message: string |
| 69 | + readonly filename?: string |
| 70 | + readonly cause?: unknown |
| 71 | +}> {} |
| 72 | + |
| 73 | +/** |
| 74 | + * Configuration error |
| 75 | + */ |
| 76 | +export class MailConfigError extends Data.TaggedError("MailConfigError")<{ |
| 77 | + readonly message: string |
| 78 | + readonly field?: string |
| 79 | +}> {} |
| 80 | + |
| 81 | +/** |
| 82 | + * Union of all mail-related errors |
| 83 | + */ |
| 84 | +export type MailSystemError = |
| 85 | + | MailError |
| 86 | + | MailConnectionError |
| 87 | + | MailValidationError |
| 88 | + | MailDeliveryError |
| 89 | + | TemplateError |
| 90 | + | TemplateNotFoundError |
| 91 | + | AttachmentError |
| 92 | + | MailConfigError |
0 commit comments