/** * @param ConsoleExceptionEvent $event */ public function onConsoleError(ConsoleExceptionEvent $event) { $exception = $event->getException(); $command = $event->getCommand(); $output = $event->getOutput(); $this->logger->error(sprintf("error while executing %s -> %s", $command->getName(), $exception->getMessage())); if ($this->config->get("common/debug")) { return; } $output->writeln(sprintf("error while executing %s -> %s", $command->getName(), $exception->getMessage())); }
/** * @param GetResponseForExceptionEvent $event */ public function onSilexError(GetResponseForExceptionEvent $event) { $exception = $event->getException(); $this->logger->error($exception->getMessage()); if ($this->config->get("common/debug")) { return; } /** * dont show error message if exception are not from http exception */ if (!$exception instanceof HttpExceptionInterface) { $event->setResponse(new JsonResponse(["error" => "Internal error"], Response::HTTP_INTERNAL_SERVER_ERROR)); return; } /** * show http exception error */ $event->setResponse(new JsonResponse(["error" => $exception->getMessage()], $exception->getStatusCode())); }