/**
* Converts a {@see \Symfony\Component\Debug\Exception\FlattenException}
* to a {@see \Dunglas\ApiBundle\JsonLd\Response}.
*
* @param FlattenException $exception
*
* @return Response
*/
public function __invoke(FlattenException $exception)
{
$exceptionClass = $exception->getClass();
if (is_a($exceptionClass, ExceptionInterface::class, true) || is_a($exceptionClass, InvalidArgumentException::class, true)) {
$exception->setStatusCode(Response::HTTP_BAD_REQUEST);
}
return new Response($this->normalizer->normalize($exception, 'hydra-error'), $exception->getStatusCode(), $exception->getHeaders());
}