From f4d5d417d0315b8d67881d7b00c0243b1823d9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 18 May 2024 20:09:33 +0800 Subject: [PATCH] build: 1.3.5 --- src/onebot11/action/BaseAction.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/onebot11/action/BaseAction.ts b/src/onebot11/action/BaseAction.ts index b4d1154a..e48fcdea 100644 --- a/src/onebot11/action/BaseAction.ts +++ b/src/onebot11/action/BaseAction.ts @@ -2,20 +2,24 @@ import { ActionName, BaseCheckResult } from './types'; import { OB11Response } from './OB11Response'; import { OB11Return } from '../types'; import { log, logError } from '../../common/utils/log'; -import Ajv from 'ajv'; +import Ajv, { ErrorObject, ValidateFunction } from 'ajv'; class BaseAction { actionName!: ActionName; - private validate: any = undefined; + private validate: undefined | ValidateFunction = undefined; PayloadSchema: any = undefined; protected async check(payload: PayloadType): Promise { if (this.PayloadSchema) { this.validate = new Ajv().compile(this.PayloadSchema); } if (this.validate && !this.validate(payload)) { + const errors = this.validate.errors as ErrorObject[]; + const errorMessages: string[] = errors.map((e) => { + return `Key: ${e.instancePath.split('/').slice(1).join('.')}, Message: ${e.message}`; + }); return { valid: false, - message: this.validate.errors?.map((e: { message: any; }) => e.message).join(',') as string + message: errorMessages.join('\n') as string || '未知错误' } } return {