Process validation error data
@param \October\Rain\Database\ModelException $obException
510553
protected function processValidationError(&$obException)
    {
        $arFiledList = array_keys($obException->getFields());

        Result::setFalse(['field' => array_shift($arFiledList)])
            ->setMessage($obException->getMessage())
            ->setCode($obException->getCode());
    }
1092387
public function onBootException(GetResponseForExceptionEvent $event)
    {
        if ($this->isProfilerRequest($event->getRequest())) {
            return;
        }

        $exception = $event->getException();
        if ($exception instanceof BootException) {
            $event->setResponse($exception->getResponse());
        }
    }
27562
protected function throwValidationException(Request $request, $validator)
    {
        throw new ResourceException($validator->errors()->first(), $validator->errors());
//        throw new ValidationException($validator, $this->buildFailedValidationResponse(
//            $request, $this->formatValidationErrors($validator)
//        ));
    }
900582
public function validate()
    {
        if ($this->isWorkflowDispatch() && null === $this->getWorkflowRunType()) {
            $errMsg = 'workflowRunType not specified';
            throw new Exception\InvalidMetadataException($errMsg);
        }

        if ($this->isFlagRunPrepareData()) {
            if (null === $this->getPrepareDataMethod()) {
                $errMsg = 'prepareDataMethod not specified';
                throw new Exception\InvalidMetadataException($errMsg);
            }
            if (null === $this->getPrepareDataMethod()) {
                $errMsg = 'prepareDataMethod not specified';
                throw new Exception\InvalidMetadataException($errMsg);
            }
        }

        if ($this->getFlagHasConditions()) {
            if (0 === count($this->getConditions())) {
                $errMsg = 'empty conditions';
                throw new Exception\InvalidMetadataException($errMsg);
            }

            foreach ($this->getConditions() as $condition) {
                $condition->validate();
            }
        }
    }
1154051
public function validate() {

		if ($this->getExternalId() === null) {
			throw new ValidationException("'externalId' can't be null", 'externalId', $this);
		}
		if ($this->getLineItems() === null) {
			throw new ValidationException("'lineItems' can't be null", 'lineItems', $this);
		}
	}
872042
public function logValidationError($validationType, $messageException = null, $method = null, $line = null)
    {
        if (self::getConfig('log', 'validation')) {
            $this->logMessage("VALIDATE][KO][{$validationType}", "{$messageException} --- " . $this->__toString() . "\n", $method, $line);
        }
        //file_put_contents('php://stderr', "[" . date('Y-m-d H:i:s') . "][VALIDATION][KO][{{$method}#{$line}][{$validationType}] : {$messageException} --- " . $this->__toString() . "\n");
    }
267402
public function validate() {

		if ($this->getAmountIncludingTax() === null) {
			throw new ValidationException("'amountIncludingTax' can't be null", 'amountIncludingTax', $this);
		}
		if ($this->getExternalId() === null) {
			throw new ValidationException("'externalId' can't be null", 'externalId', $this);
		}
		if ($this->getQuantity() === null) {
			throw new ValidationException("'quantity' can't be null", 'quantity', $this);
		}
		if ($this->getSubscriptionVersion() === null) {
			throw new ValidationException("'subscriptionVersion' can't be null", 'subscriptionVersion', $this);
		}
		if ($this->getTitle() === null) {
			throw new ValidationException("'title' can't be null", 'title', $this);
		}
	}
897664
public function onException(GetResponseForExceptionEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $attributes = $event->getRequest()->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        $exception = $event->getException();
        if ($exception instanceof HttpExceptionInterface) {
            return;
        }

        $exceptionClass = null;
        foreach ($this->exceptionMap as $sourceException => $targetException) {
            if (is_a($exception, $sourceException, true)) {
                $exceptionClass = $targetException;

                break;
            }
        }

        if ($exceptionClass !== null) {
            $convertedException = new $exceptionClass(
                $exception->getMessage(),
                $exception,
                $exception->getCode()
            );

            $event->setException($convertedException);
        }
    }
1225433
public function onException(GetResponseForExceptionEvent $event): void
    {
        $attributes = $event->getRequest()->attributes;
        if ($attributes->get(SetIsAdminRequestListener::ADMIN_FLAG_NAME) !== true) {
            return;
        }

        if (!$event->getRequest()->isXmlHttpRequest()) {
            return;
        }

        $exception = $event->getException();
        if (!$exception instanceof AuthenticationException && !$exception instanceof AccessDeniedException) {
            return;
        }

        $event->setException(new AccessDeniedHttpException());

        $event->stopPropagation();
    }
45171
public function validateUpdateDocument()
    {
        $this->_documentMustHavePrimaryData();
        $this->_primaryDataMustHaveType();
        $this->_primaryDataMustHaveId();
        $this->_primaryDataMayHaveRelationships();

        if ($this->_errorCollection->count() === 0) {
            return;
        }

        throw new ValidationException($this->_getErrorCollectionEntity());
    }
85314
public function validate($value)
    {
        // if value required, then only valueTrue is allowed
        if ($this->required && $value !== $this->valueTrue) {
            throw new ValidationException([$this->name => 'Must be selected']);
        }
    }
496112
private function throwExceptionIfErrors(ConstraintViolationListInterface $errors): void
    {
        if (0 === $errors->count()) {
            return;
        }
        throw ValidationException::create($errors, $this->dataObject);
    }
611503
public function onError(GetResponseForExceptionEvent $event)
    {
        if ($event->getRequest()->isXmlHttpRequest()) {
            $exception = $event->getException();
            if ($exception instanceof InvalidDataException) {
                // return correct status code for invalid data sent by the user
                $response = new JsonResponse($exception->getErrors(), 422);
            } else {
                $response = new JsonResponse([
                    'message' => $exception->getMessage(),
                    'trace' => $exception->getTrace(),
                    //if <200, not http error code
                ], $exception->getCode() < 200 ? 500 : $exception->getCode());
            }

            $event->setResponse($response);
        }
    }
1036446
public function validation($exception)
    {
        if (!$this->controller->request->accepts('application/vnd.api+json')) {
            return parent::validation($exception);
        }

        $status = $exception->getCode();

        try {
            $this->controller->response = $this->controller->response->withStatus($status);
        } catch (Exception $e) {
            $status = 422;
            $this->controller->response = $this->controller->response->withStatus($status);
        }

        $errorCollection = $this->_getNeoMerxErrorCollection($exception->getValidationErrors());

        $encoder = Encoder::instance();
        $json = $encoder->encodeErrors($errorCollection);

        if (Configure::read('debug')) {
            $json = $this->_addDebugNode($json);
            $json = $this->_addQueryLogsNode($json);
        }

        # create stream as required by `response->withBody()`
        $stream = new Stream('php://memory', 'wb+');
        $stream->write($json);

        // set up the response
        $this->controller->response = $this->controller->response
            ->withType('jsonapi')
            ->withBody($stream);

        return $this->controller->response;
    }
1189216
protected function validateObject($object)
    {
        $classSchema = $this->reflectionService->getClassSchema($object);
        $validator = $this->validatorResolver->getBaseValidatorConjunction($classSchema->getClassName());
        if ($validator === null) {
            return;
        }
        $validationResult = $validator->validate($object);
        if ($validationResult->hasErrors()) {
            $errorMessages = '';
            $allErrors = $validationResult->getFlattenedErrors();
            foreach ($allErrors as $path => $errors) {
                $errorMessages .= $path . ':' . PHP_EOL;
                foreach ($errors as $error) {
                    $errorMessages .= (string)$error . PHP_EOL;
                }
            }
            throw new ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585162);
        }
    }
893150
public function onException(GetResponseForExceptionEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $attributes = $event->getRequest()->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        $exception = $event->getException();

        if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
            $this->logger->critical(
                sprintf(
                    'Uncaught PHP Exception %s: "%s" at %s line %s',
                    get_class($exception),
                    $exception->getMessage(),
                    $exception->getFile(),
                    $exception->getLine()
                ),
                ['exception' => $exception]
            );
        }

        $response = new JsonResponse();
        $response->setContent($this->serializer->serialize($exception, 'json'));

        $event->setResponse($response);
    }
477849
protected function validateModel()
    {
        if (!$this->model) {
            throw new ApplicationException(Lang::get(
                'backend::lang.list.missing_model',
                ['class'=>get_class($this->controller)]
            ));
        }

        if (!$this->model instanceof Model) {
            throw new ApplicationException(Lang::get(
                'backend::lang.model.invalid_class',
                ['model'=>get_class($this->model), 'class'=>get_class($this->controller)]
            ));
        }

        return $this->model;
    }