feat(ops): add client error reporting API and frontend hooks

Collect mini-user/shop/partner JS errors via POST /common/client-errors, persist logs, and push fatal/error to WeCom.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-02 16:27:08 +08:00
parent 3328c52cb4
commit 205c1110c2
11 changed files with 520 additions and 0 deletions
@@ -0,0 +1,25 @@
import { Body, Controller, Headers, Post, UseGuards } from '@nestjs/common';
import { OptionalJwtAuthGuard } from '../../common/guards/optional-jwt-auth.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import type { AuthUser } from '../../common/guards/jwt-auth.guard';
import { ClientErrorService } from './client-error.service';
import { ReportClientErrorDto } from './dto/client-error.dto';
@Controller('common')
export class ClientErrorController {
constructor(private readonly clientErrors: ClientErrorService) {}
/**
* 客户端报错上报(可匿名)。
* fatal/error → Nest 日志 + 落库 + 企微;warn → 仅日志/落库。
*/
@Post('client-errors')
@UseGuards(OptionalJwtAuthGuard)
report(
@Body() dto: ReportClientErrorDto,
@CurrentUser() user: AuthUser | undefined,
@Headers('x-client-app') clientApp?: string,
) {
return this.clientErrors.report(dto, user, clientApp);
}
}