Merge branch 'next' into develop

This commit is contained in:
nocobase[bot]
2026-02-28 11:25:29 +00:00
@@ -7,8 +7,6 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { Schema } from '@formily/json-schema';
import { BaseError } from '@nocobase/database';
import { Plugin } from '@nocobase/server';
import lodash from 'lodash';
import { ErrorHandler } from './error-handler';
@@ -19,10 +17,11 @@ export class PluginErrorHandlerServer extends Plugin {
beforeLoad() {
this.registerSequelizeValidationErrorHandler();
this.registerSQLErrorHandler();
}
registerSequelizeValidationErrorHandler() {
const findFieldTitle = (instance, path, tFunc, ctx) => {
const findFieldTitle = (instance, path, ctx) => {
if (!instance) {
return path;
}
@@ -39,9 +38,11 @@ export class PluginErrorHandlerServer extends Plugin {
}
const field = collection.getField(path);
const fieldOptions = Schema.compile(field?.options, { t: tFunc });
const fieldOptions = field?.options;
const title = lodash.get(fieldOptions, 'uiSchema.title', path);
return title;
const re = /{{\s*t\(\s*(['"`])([^'"`]+)\1\s*\)\s*}}/g;
const parsed = re.exec(title);
return parsed?.[2] || title;
};
this.errorHandler.register(
@@ -52,7 +53,7 @@ export class PluginErrorHandlerServer extends Plugin {
ctx.body = {
errors: err.errors.map((err) => {
const t = ctx.i18n.t;
const title = findFieldTitle(err.instance, err.path, t, ctx);
const title = findFieldTitle(err.instance, err.path, ctx);
return {
message: t(err.type, {
ns: this.i18nNs,
@@ -64,7 +65,9 @@ export class PluginErrorHandlerServer extends Plugin {
ctx.status = 400;
},
);
}
registerSQLErrorHandler() {
const unwrapSqlError = (error) => {
return error?.original?.parent ?? error?.parent ?? error?.original ?? error;
};