import { ErrorCode } from "@batch-cooking/shared"; import i18n from "../i18n/i18n"; /** * Localized label for an {@link ErrorCode} returned by the admin API — * verbatim behaviour of apps/web's `ErrorMessageService`: reverse-maps the * numeric enum value to its member name (`4010` → `"INVALID_CREDENTIALS"`) * and looks it up under the `errors` namespace, falling back to * `INTERNAL_ERROR` for a code this client doesn't recognise. */ export class ErrorMessageService { public getLabel(code: ErrorCode): string { const memberName = ErrorCode[code] ?? ErrorCode[ErrorCode.INTERNAL_ERROR]; return i18n.t(`errors.${memberName}`); } } /** Single shared instance — stateless. */ export const errorMessageService = new ErrorMessageService();