Skip to content

Commit

Permalink
FEATURE: Log query exceptions
Browse files Browse the repository at this point in the history
The GraphQL library I use (webonyx/graphql-php) conveniently
converts any exceptions into a GraphQL "error result".
This leads to the exception handler not being triggered any longer.

With this change any exception that occurs during processing of a GraphQL
query is logged using the Flow `SystemLogger`.
  • Loading branch information
bwaidelich committed Sep 1, 2016
1 parent 2d6996e commit ba19883
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Classes/View/GraphQlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
use GraphQL\Executor\ExecutionResult;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Http\Response as HttpResponse;
use TYPO3\Flow\Log\SystemLoggerInterface;
use TYPO3\Flow\Mvc\View\AbstractView;
use TYPO3\Flow\Exception as FlowException;

class GraphQlView extends AbstractView
{

/**
* @Flow\Inject
* @var SystemLoggerInterface
*/
protected $systemLogger;

/**
* @return string The rendered view
* @throws FlowException
Expand Down Expand Up @@ -57,6 +64,9 @@ private function formatResult(ExecutionResult $executionResult)
$errorResult['_statusCode'] = $exception->getStatusCode();
$errorResult['_referenceCode'] = $exception->getReferenceCode();
}
if ($exception instanceof \Exception) {
$this->systemLogger->logException($exception);
}
return $errorResult;
}, $executionResult->errors);
}
Expand Down

0 comments on commit ba19883

Please sign in to comment.