feat: surface expression validation errors when creating or updating rules

This commit is contained in:
Michael Thomas
2024-03-07 12:23:32 -05:00
parent b572c1dcd3
commit 438f602961
7 changed files with 58 additions and 14 deletions

View File

@@ -74,15 +74,14 @@ class ExpressionController extends Controller
$expressionLanguage = ExpressionLanguageFactory::get();
$evaluator = new ActionExpressionEvaluator($expressionLanguage, $expr);
try {
$evaluator->lint();
if ($evaluator->isValid()) {
return response()->json([
"valid" => true,
]);
} catch (SyntaxError $e) {
} else {
return response()->json([
"valid" => false,
"error" => $e->getMessage()
"error" => $evaluator->getValidationError()->getMessage()
]);
}
}