/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var Context $context */ if (!$context->hasErrors()) { // no errors return; } $errors = $context->getErrors(); $error = $errors[0]; $exception = $error->getInnerException(); if (null !== $exception) { $underlyingException = ExceptionUtil::getProcessorUnderlyingException($exception); if ($underlyingException instanceof HttpExceptionInterface) { $exception = $underlyingException; } } else { $message = $error->getDetail(); if (empty($message)) { $message = $error->getTitle(); } if (empty($message)) { $message = 'Unknown error.'; } $exception = new \RuntimeException($message); } throw $exception; }
/** * @param string $dataType * @param string[] $requestType * @param mixed|null $value * @param bool $isArrayAllowed * * @return NormalizeValueContext * @throws \Exception */ protected function doNormalization($dataType, array $requestType, $value = null, $isArrayAllowed = false) { /** @var NormalizeValueContext $context */ $context = $this->processor->createContext(); $context->setRequestType($requestType); $context->setDataType($dataType); $context->setResult($value); $context->setArrayAllowed($isArrayAllowed); try { $this->processor->process($context); } catch (\Exception $e) { throw ExceptionUtil::getProcessorUnderlyingException($e); } return $context; }
/** * Sets an exception object that caused this occurrence of the problem. * * @param \Exception $exception */ public function setInnerException(\Exception $exception) { $this->innerException = $exception; if (null === $this->statusCode) { $this->statusCode = ExceptionUtil::getExceptionStatusCode($exception); } if (null === $this->detail) { $this->detail = $exception->getMessage(); } }