Skip to content
GitHub

ValidationError

class in meocord/common Since 4.1.0

class ValidationError extends Error

Thrown 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

TypeScript
@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

NameTypeDescription
issuesValidationIssue[]

Every problem found, in the order the schema reported them.

issues

readonly issues: ValidationIssue[]

fromSchemaIssues

static fromSchemaIssues(
  issues: readonly StandardSchemaV1Issue[],
): ValidationError

The issues a Standard Schema reported, with each path reduced to its keys.

Parameters

NameTypeDescription
issuesreadonly StandardSchemaV1Issue[]

The issues, as the schema's validate reported them.

Returns

ValidationError

The error, its issues in the schema's order.

See also