(error, t, uischema)
| 86 | ); |
| 87 | |
| 88 | export 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…