Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as R from 'rambda';
import * as ts from '@terascope/utils';
import ajv from 'ajv';
export const getErrorMessages: (errors: ErrorLike[]) => string = R.pipe(
R.map(getErrorMessage),
R.join(', ')
);
export function throwValidationError(errors: ErrorLike[] | null | undefined): string | null {
if (errors == null) return null;
if (!errors.length) return null;
const errorMsg = getErrorMessages(errors);
const error = new ts.TSError(errorMsg, {
statusCode: 400,
});
Error.captureStackTrace(error, throwValidationError);
throw error;
}