From d0f51d881594bf1b68dd0c0d2c8cbfad9d92bd27 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 26 Mar 2020 21:29:51 +0000 Subject: [PATCH] fix: added more guard clauses around the endpoint (#2910) Co-authored-by: Kim Gardner --- src/core/server/services/perspective/perspective.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/server/services/perspective/perspective.ts b/src/core/server/services/perspective/perspective.ts index bbcac43ef..301bd00f6 100644 --- a/src/core/server/services/perspective/perspective.ts +++ b/src/core/server/services/perspective/perspective.ts @@ -34,7 +34,7 @@ function convertLanguage(locale: LanguageCode): PerspectiveLanguage { } interface Options { - endpoint?: string; + endpoint?: string | null; key: string; timeout: number; } @@ -117,11 +117,11 @@ function formatBody(req: Request): object { } export async function sendToPerspective( - { endpoint = TOXICITY_ENDPOINT_DEFAULT, key, timeout }: Options, + { endpoint, key, timeout }: Options, req: Request ) { // Prepare the URL to send the command to. - const url = new URL(endpoint.trim()); + const url = new URL((endpoint || TOXICITY_ENDPOINT_DEFAULT).trim()); url.pathname = path.join(url.pathname, `/${req.operation}`); url.searchParams.set("key", key.trim());