@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
||||
|
||||
import type { Locale } from "@conusai-kit/i18n"
|
||||
import { serviceNotice } from "@conusai-kit/ui/patterns"
|
||||
import { ZodError } from "zod"
|
||||
import type { en } from "../i18n/en.js"
|
||||
export type Messages = { [K in keyof typeof en]: string }
|
||||
/**
|
||||
* What the loader hands the views: the module's messages, the reader's locale (money is formatted with it) and
|
||||
* the kit's refusal sentences by problem code (`businessRefusalNotices` of `@conusai-kit/business/refusals`).
|
||||
*/
|
||||
export type Labels = Messages & { readonly locale: Locale; readonly refusals: Readonly<Record<string, string>> }
|
||||
export function describeFailure(error: unknown, labels: Labels): string {
|
||||
if (error instanceof ZodError) return labels.invalid
|
||||
return serviceNotice(error, labels.refusals)?.text ?? labels.unavailable
|
||||
}
|
||||
Reference in New Issue
Block a user