This commit is contained in:
MomentQYC 2023-08-16 11:36:02 +08:00
parent 14df563c7d
commit d1f7f22068
4 changed files with 1 additions and 21 deletions

View File

@ -1,13 +0,0 @@
/*
* SPDX-FileCopyrightText: MomentQYC and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { FastifyReply, FastifyRequest } from 'fastify';
export async function ErrorHandler(error: Error, request: FastifyRequest, reply: FastifyReply): Promise<void> {
if (process.env.NODE_ENV === 'production') {
error.stack = undefined;
}
reply.send(error);
throw error;
}

View File

@ -12,9 +12,5 @@ export class FastifyReplyError extends Error {
super(message);
this.message = message;
this.statusCode = statusCode;
if (process.env.NODE_ENV === 'production') {
Object.defineProperty(this, 'stack', { value: undefined });
}
}
}

View File

@ -22,7 +22,6 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
import { MetaService } from '@/core/MetaService.js';
import { ErrorHandler } from '@/misc/error.js';
import { ActivityPubServerService } from './ActivityPubServerService.js';
import { NodeinfoServerService } from './NodeinfoServerService.js';
import { ApiServerService } from './api/ApiServerService.js';
@ -77,7 +76,6 @@ export class ServerService implements OnApplicationShutdown {
logger: !['production', 'test'].includes(process.env.NODE_ENV ?? ''),
});
this.#fastify = fastify;
fastify.setErrorHandler(ErrorHandler);
// HSTS
// 6months (15552000sec)

View File

@ -682,13 +682,12 @@ export class ClientServerService {
fastify.setErrorHandler(async (error, request, reply) => {
const errId = randomUUID();
const stack = (process.env.NODE_ENV === 'production') ? '' : error.stack;
this.clientLoggerService.logger.error(`Internal error occurred in ${request.routerPath}: ${error.message}`, {
path: request.routerPath,
params: request.params,
query: request.query,
code: error.name,
stack,
stack: error.stack,
id: errId,
});
reply.code(500);