This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-5818: GraphQl-220: Implement exception logging #355
- Loading branch information
Showing
4 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Magento\Framework\GraphQl\Query\ErrorHandlerInterface" type="Magento\Framework\GraphQl\Query\ErrorHandler"/> | ||
</config> |
48 changes: 48 additions & 0 deletions
48
lib/internal/Magento/Framework/GraphQl/Query/ErrorHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\GraphQl\Query; | ||
|
||
use GraphQL\Error\ClientAware; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @package Magento\Framework\GraphQl\Query | ||
*/ | ||
class ErrorHandler implements ErrorHandlerInterface | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
LoggerInterface $logger | ||
) { | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function handle(array $errors, callable $formatter): array | ||
{ | ||
return array_map( | ||
function (ClientAware $error) use ($formatter) { | ||
$this->logger->error($error); | ||
|
||
return $formatter($error); | ||
}, | ||
$errors | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
lib/internal/Magento/Framework/GraphQl/Query/ErrorHandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\GraphQl\Query; | ||
|
||
use GraphQL\Error\Error; | ||
|
||
/** | ||
* Interface ErrorHandlerInterface | ||
* | ||
* GraphQL error handler | ||
* | ||
* @see \Magento\Framework\GraphQl\Query\QueryProcessor | ||
* | ||
* @api | ||
*/ | ||
interface ErrorHandlerInterface | ||
{ | ||
/** | ||
* Handle errors | ||
* | ||
* @param Error[] $errors | ||
* @param callable $formatter | ||
* | ||
* @return array | ||
*/ | ||
public function handle(array $errors, callable $formatter): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters