Log errors

This commit is contained in:
artrejo 2022-01-21 18:20:22 -08:00
parent 16bb03c47c
commit 54cd7a32d8

View File

@ -1,7 +1,11 @@
import * as Logger from "../Common/Logger";
export function validateEndpoint(endpointToValidate: string | undefined, allowedEndpoints: string[]): boolean { export function validateEndpoint(endpointToValidate: string | undefined, allowedEndpoints: string[]): boolean {
try { try {
return validateEndpointInternal(endpointToValidate, allowedEndpoints); return validateEndpointInternal(endpointToValidate, allowedEndpoints);
} catch { } catch (reason) {
Logger.logError(`${endpointToValidate} not allowed`, "validateEndpoint");
Logger.logError(`${JSON.stringify(reason)}`, "validateEndpoint");
return false; return false;
} }
} }
@ -16,7 +20,9 @@ function validateEndpointInternal(endpointToValidate: string | undefined, allowe
const valid = allowedOrigins.indexOf(originToValidate) >= 0; const valid = allowedOrigins.indexOf(originToValidate) >= 0;
if (!valid) { if (!valid) {
console.error(`${endpointToValidate} not allowed`); throw new Error(
`${endpointToValidate} is not an allowed endpoint. Allowed endpoints are ${allowedArmEndpoints.toString()}`
);
} }
return valid; return valid;