import { FastifyInstance } from "fastify" ; import AppError from "src/common/AppError" ; param fastify export default async function hooks ( fastify ) { fastify . setErrorHandler ( function ( error , request , reply ) { reply . hijack ( ) ; if ( error instanceof AppError ) { reply . send ( { code : 200 , msg : error . message , } ) ; } else { reply . send ( { code : 500 , msg : process . env . NODE_ENV === "development" ? error . message : "系统异常，请联系管理员" , } ) ; } } ) ; }