feat(server): 新增统一 logger 入口与 /health liveness 端点
- src/server/logger.ts 包一层 console.*,给后续 pino/otel 迁移留单点 - interceptors.ts 的 logError 改走 logger.error,业务侧禁止直接 console.* - /health 返回 'ok',纯 liveness(不查 DB),DB 挂时探活仍绿
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { ORPCError, ValidationError } from '@orpc/server'
|
||||
import { z } from 'zod'
|
||||
import { logger } from '@/server/logger'
|
||||
|
||||
export const logError = (error: unknown) => {
|
||||
console.error(error)
|
||||
logger.error(error)
|
||||
}
|
||||
|
||||
export const handleValidationError = (error: unknown) => {
|
||||
if (error instanceof ORPCError && error.code === 'BAD_REQUEST' && error.cause instanceof ValidationError) {
|
||||
// If you only use Zod you can safely cast to ZodIssue[] (per ORPC official docs)
|
||||
// ORPC ValidationError.issues are Zod issues in this app.
|
||||
const zodError = new z.ZodError(error.cause.issues as z.core.$ZodIssue[])
|
||||
|
||||
throw new ORPCError('INPUT_VALIDATION_FAILED', {
|
||||
|
||||
Reference in New Issue
Block a user