From 86c033bdaaf3470da4b587dd62ba718dcc5cd300 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 21 Sep 2023 16:32:08 +0400 Subject: [PATCH] Use common getConfig() --- src/errors/handler.ts | 6 +++++- src/errors/main.ts | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/errors/handler.ts b/src/errors/handler.ts index 909757a..5d28722 100644 --- a/src/errors/handler.ts +++ b/src/errors/handler.ts @@ -3,6 +3,7 @@ import { NotHtmlMimetypeError, TxtDotError } from "./main"; import { getFastifyError } from "./validation"; import { IGetSchema } from "../types/requests/browser"; +import getConfig from "../config/main"; export default function errorHandler( error: Error, @@ -54,7 +55,10 @@ function htmlErrorHandler(error: Error, reply: FastifyReply, url: string) { url, code: error.code, description: error.description, - proxyBtn: error instanceof NotHtmlMimetypeError, + proxyBtn: ( + error instanceof NotHtmlMimetypeError && + getConfig().proxy_res + ), }); } diff --git a/src/errors/main.ts b/src/errors/main.ts index bee68f3..81f983a 100644 --- a/src/errors/main.ts +++ b/src/errors/main.ts @@ -1,3 +1,5 @@ +import getConfig from "../config/main"; + export abstract class TxtDotError extends Error { code: number; name: string; @@ -40,7 +42,11 @@ export class NotHtmlMimetypeError extends TxtDotError { super( 421, "NotHtmlMimetypeError", - "Received non-HTML content, use proxy", + "Received non-HTML content, " + ( + getConfig().proxy_res ? + "use proxy instead of parser." : + "proxying is disabled by the instance admin." + ), ); } }