MCPcopy Create free account
hub / github.com/eclipsesource/jsonforms / defaultErrorTranslator

Function defaultErrorTranslator

packages/core/src/i18n/i18nUtil.ts:88–124  ·  view source on GitHub ↗
(error, t, uischema)

Source from the content-addressed store, hash-verified

86);
87
88export const defaultErrorTranslator: ErrorTranslator = (error, t, uischema) => {
89 // check whether there is a special keyword message
90 const i18nKey = getI18nKey(
91 error.parentSchema,
92 uischema,
93 getControlPath(error),
94 `error.${error.keyword}`
95 );
96 const specializedKeywordMessage = t(i18nKey, undefined, { error });
97 if (specializedKeywordMessage !== undefined) {
98 return specializedKeywordMessage;
99 }
100
101 // check whether there is a generic keyword message
102 const genericKeywordMessage = t(`error.${error.keyword}`, undefined, {
103 error,
104 });
105 if (genericKeywordMessage !== undefined) {
106 return genericKeywordMessage;
107 }
108
109 // check whether there is a customization for the default message
110 const messageCustomization = t(error.message, undefined, { error });
111 if (messageCustomization !== undefined) {
112 return messageCustomization;
113 }
114
115 // rewrite required property messages (if they were not customized) as we place them next to the respective input
116 if (
117 error.keyword === 'required' &&
118 error.message?.startsWith('must have required property')
119 ) {
120 return t('is a required property', 'is a required property', { error });
121 }
122
123 return error.message;
124};
125
126/**
127 * Returns the determined error message for the given errors.

Callers

nothing calls this directly

Calls 2

getControlPathFunction · 0.90
getI18nKeyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…