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

View File

@ -14,7 +14,7 @@ export class FastifyReplyError extends Error {
this.statusCode = statusCode; this.statusCode = statusCode;
if (process.env.NODE_ENV === 'production') { 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> { public async createServer(fastify: FastifyInstance): Promise<void> {
// https://datatracker.ietf.org/doc/html/rfc8414.html // https://datatracker.ietf.org/doc/html/rfc8414.html
// https://indieauth.spec.indieweb.org/#indieauth-server-metadata // https://indieauth.spec.indieweb.org/#indieauth-server-metadata
fastify.get('/.well-known/oauth-authorization-server', async (_request, reply) => { fastify.get('/.well-known/oauth-authorization-server', async (_request, reply) => {
reply.send({ reply.send({
issuer: this.config.url, issuer: this.config.url,