You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add formatError function which would format the error into a human readable string
Add some extra metadata to the error about the failure such as { expected: 'int32', actual 'string' } or { expected: 'found', actual: 'missing' }, or whatever is needed to give a readable explanation to a user.
exportclassValidationErrorextendsError{constructor(publicreadonlyschemaName: string,publicreadonlyerrors: SchemaValidationError[],){super(`A validation error occurred for type ${this.schemaName}`)this.name="ValidationError";}}
Theoretically I can use the instance path to identify the exact field, so if I was in a UI form I could essentially attach the formatted error onto the form element for display.
You have a bit of a name conflict where your return type from the validate function is ValidationError, which in javascript the word Error is reserved for types which extend the Error class. So seems like that should be renamed to something else and then the actual ValidationError should look similar to the above.
The text was updated successfully, but these errors were encountered:
justinmchase
changed the title
It would be nice if this package had a ValidationError and error formatter
It would be nice if this package had a throwable ValidationError and error formatter
Apr 15, 2023
ValidationError
classformatError
function which would format the error into a human readable string{ expected: 'int32', actual 'string' }
or{ expected: 'found', actual: 'missing' }
, or whatever is needed to give a readable explanation to a user.Theoretically I can use the instance path to identify the exact field, so if I was in a UI form I could essentially attach the formatted error onto the form element for display.
You have a bit of a name conflict where your return type from the validate function is
ValidationError
, which in javascript the word Error is reserved for types which extend the Error class. So seems like that should be renamed to something else and then the actualValidationError
should look similar to the above.The text was updated successfully, but these errors were encountered: