change and fix

This commit is contained in:
MomentQYC 2023-08-14 21:43:12 +08:00
parent 0ea386effe
commit 14df563c7d
4 changed files with 4 additions and 18 deletions

View File

@ -1,6 +0,0 @@
/*
* SPDX-FileCopyrightText: tamaina and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
// Never use `./error.js` because jest can't use it.

View File

@ -4,17 +4,10 @@
*/
import { FastifyReply, FastifyRequest } from 'fastify';
export function ErrorHandling(message: string, reply?: FastifyReply, statusCode?: number): Error {
const error = new Error(message);
export async function ErrorHandler(error: Error, request: FastifyRequest, reply: FastifyReply): Promise<void> {
if (process.env.NODE_ENV === 'production') {
error.stack = undefined;
}
if (reply) {
reply.code(statusCode ?? 500);
}
return error;
}
export function ErrorHandler(error: Error, request: FastifyRequest, reply: FastifyReply): void {
throw ErrorHandling(error.message, reply);
reply.send(error);
throw error;
}

View File

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

View File

@ -353,7 +353,6 @@ export class OAuth2ProviderService {
public async createServer(fastify: FastifyInstance): Promise<void> {
// https://datatracker.ietf.org/doc/html/rfc8414.html
// https://indieauth.spec.indieweb.org/#indieauth-server-metadata
fastify.get('/.well-known/oauth-authorization-server', async (_request, reply) => {
reply.send({
issuer: this.config.url,