fix: added more guard clauses around the endpoint (#2910)

Co-authored-by: Kim Gardner <kgardnr@gmail.com>
This commit is contained in:
Wyatt Johnson
2020-03-26 17:29:51 -04:00
committed by GitHub
co-authored by Kim Gardner
parent b228725370
commit d0f51d8815
@@ -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());