fix(admin,api): 上分超额提示而非静默截断,并返回中文业务错误

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-08 15:47:45 +08:00
parent 414998ce36
commit 22535d4c27
8 changed files with 97 additions and 29 deletions

View File

@@ -4,10 +4,12 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
import { AppModule } from './app.module';
import { GlobalExceptionFilter } from './shared/common/filters';
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.enableShutdownHooks();
app.useGlobalFilters(new GlobalExceptionFilter());
const uploadDir = process.env.UPLOAD_DIR || join(__dirname, '..', '..', 'uploads');
app.useStaticAssets(uploadDir, { prefix: '/uploads/' });

View File

@@ -20,7 +20,16 @@ export class GlobalExceptionFilter implements ExceptionFilter {
if (exception instanceof HttpException) {
status = exception.getStatus();
const res = exception.getResponse();
message = typeof res === 'string' ? res : (res as { message?: string }).message || message;
if (typeof res === 'string') {
message = res;
} else if (typeof res === 'object' && res !== null) {
const body = res as { message?: string | string[] };
if (Array.isArray(body.message)) {
message = body.message.join('');
} else if (typeof body.message === 'string' && body.message.trim()) {
message = body.message;
}
}
} else if (exception instanceof Error) {
message = exception.message;
}