ValidationError
class in meocord/common Since 4.1.0
class ValidationError extends ErrorThrown when a handler's input fails its @Validate schema, so the handler does not run.
The built-in fallback answers with each issue, privately for an interaction and as a reply to a message command. Catch it in a filter to phrase the issues your own way, or in the user's language.
Examples
@Catch(ValidationError)
export class ValidationFilter implements ExceptionFilter<ValidationError> {
async catch(error: ValidationError, context: ExecutionContext) {
const lines = error.issues.map(issue => `${issue.path.map(String).join('.') || 'input'}: ${issue.message}`)
await context.response?.error(error, { message: lines.join('\n') })
}
}Members
constructor
new ValidationError(issues: ValidationIssue[])Parameters
| Name | Type | Description |
|---|---|---|
issues | ValidationIssue[] | Every problem found, in the order the schema reported them. |
issues
readonly issues: ValidationIssue[]fromSchemaIssues
static fromSchemaIssues(
issues: readonly StandardSchemaV1Issue[],
): ValidationErrorThe issues a Standard Schema reported, with each path reduced to its keys.
Parameters
| Name | Type | Description |
|---|---|---|
issues | readonly StandardSchemaV1Issue[] | The issues, as the schema's |
Returns
ValidationErrorThe error, its issues in the schema's order.
See also
- Validate
- ValidationIssue