Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExceptionFormatter.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 use Psr\Log\LoggerInterface;
13 
18 {
20 
24  private $appState;
25 
29  private $logger;
30 
35  public function __construct(State $appState, ErrorProcessor $errorProcessor, LoggerInterface $logger)
36  {
37  $this->appState = $appState;
38  $errorProcessor->registerShutdownFunction();
39  $this->logger = $logger;
40  }
41 
53  public function create(\Throwable $exception, $internalErrorMessage = null) : array
54  {
55  if (!$this->shouldShowDetail()) {
56  $reportId = uniqid("graph-ql-");
57  $message = "Report ID: {$reportId}; Message: {$exception->getMessage()}";
58  $code = $exception->getCode();
59  $loggedException = new \Exception($message, $code, $exception);
60  $this->logger->critical($loggedException);
61  }
62 
63  return \GraphQL\Error\FormattedError::createFromException(
64  $exception,
65  $this->shouldShowDetail()
66  ? \GraphQL\Error\Debug::INCLUDE_DEBUG_MESSAGE | \GraphQL\Error\Debug::INCLUDE_TRACE : false,
67  $internalErrorMessage
68  );
69  }
70 
76  public function shouldShowDetail() : bool
77  {
78  return $this->appState->getMode() === State::MODE_DEVELOPER;
79  }
80 }
__construct(State $appState, ErrorProcessor $errorProcessor, LoggerInterface $logger)
$message
$logger
create(\Throwable $exception, $internalErrorMessage=null)
$code
Definition: info.phtml:12