Skip to content

Commit

Permalink
Remap ajv-errors custom messages as regular messages
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg authored and torifat committed Apr 12, 2022
1 parent e202d17 commit d4b09f0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const isXError = x => (error /*: Error */) => error.keyword === x;
export const isRequiredError = isXError('required');
export const isAnyOfError = isXError('anyOf');
export const isEnumError = isXError('enum');
export const getErrors = (node /*: Node*/) => (node && node.errors) || [];
export const getErrors = (node /*: Node*/) =>
node && node.errors
? node.errors.map(e =>
e.keyword === 'errorMessage'
? { ...e.params.errors[0], message: e.message }
: e
)
: [];

// Node
export const getChildren = (node /*: Node*/) /*: $ReadOnlyArray<Node>*/ =>
Expand Down

0 comments on commit d4b09f0

Please sign in to comment.