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,48 @@
import { IsIn, IsObject, IsOptional, IsString, MaxLength } from 'class-validator';
/** 客户端报错严重级别 */
export const CLIENT_ERROR_LEVELS = ['fatal', 'error', 'warn'] as const;
export type ClientErrorLevel = (typeof CLIENT_ERROR_LEVELS)[number];
/** 客户端报错类别 */
export const CLIENT_ERROR_CATEGORIES = [
'js_error',
'unhandled_rejection',
'api_error',
'network',
'render',
'bridge',
'other',
] as const;
export type ClientErrorCategory = (typeof CLIENT_ERROR_CATEGORIES)[number];
export class ReportClientErrorDto {
@IsIn(CLIENT_ERROR_LEVELS)
level!: ClientErrorLevel;
@IsIn(CLIENT_ERROR_CATEGORIES)
category!: ClientErrorCategory;
@IsString()
@MaxLength(1000)
message!: string;
@IsOptional()
@IsString()
@MaxLength(4000)
stack?: string;
@IsOptional()
@IsString()
@MaxLength(128)
pagePath?: string;
@IsOptional()
@IsString()
@MaxLength(64)
clientApp?: string;
@IsOptional()
@IsObject()
extra?: Record<string, unknown>;
}