Line data Source code
1 : import { zErrorResponse } from '@comfyorg/ingest-types/zod'
2 :
3 : import type { BillingServerCode } from './billingContracts'
4 :
5 : /**
6 : * The `code` of a generated `ErrorResponse` body, or nothing. This decode is
7 : * the only place a `BillingServerCode` is minted, and the brand it carries is
8 : * erased at runtime.
9 : */
10 0 : export function readBillingErrorCode(
11 : body: unknown
12 : ): BillingServerCode | undefined {
13 0 : const parsed = zErrorResponse.safeParse(body)
14 0 : return parsed.success ? (parsed.data.code as BillingServerCode) : undefined
15 : }
16 :
17 : /**
18 : * The `message` of a generated `ErrorResponse` body, or nothing when the body
19 : * is not that contract or the message is blank.
20 : */
21 0 : export function readBillingErrorMessage(body: unknown): string | undefined {
22 0 : const parsed = zErrorResponse.safeParse(body)
23 0 : if (!parsed.success) return undefined
24 0 : const message = parsed.data.message.trim()
25 0 : return message === '' ? undefined : message
26 : }
|