This repository was archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 148
GraphQl-220: Implement exception logging #355
Merged
magento-engcom-team
merged 11 commits into
magento:2.3-develop
from
novikor:Implement-exception-logging#220
Sep 10, 2019
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
583ff11
Implement exception logging #220.
9027c50
Implement exception logging #220.
6500eaf
Merge remote-tracking branch 'upstream/2.3-develop' into Implement-ex…
8de22af
Merge remote-tracking branch 'remotes/origin/2.3-develop' into Implem…
vpodorozh d40388e
GraphQl-220: Implement exception logging #355.
6a5c7e2
GraphQl-220: Implement exception logging #355.
1259496
GraphQl-220: Implement exception logging.
novikor 7de8701
Merge remote-tracking branch 'origin/2.3-develop' into Implement-exce…
novikor 7f8170c
Merge branch '2.3-develop' into Implement-exception-logging#220
9553775
GraphQl-220: Implement exception logging.
860e239
GraphQl-220: Implement exception logging.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
102 changes: 102 additions & 0 deletions
102
lib/internal/Magento/Framework/GraphQl/Query/ErrorHandler.php
This file contains hidden or 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,102 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\Framework\GraphQl\Query; | ||
|
|
||
| /** | ||
| * Class ErrorHandler | ||
| * | ||
| * @package Magento\Framework\GraphQl\Query | ||
| */ | ||
| class ErrorHandler implements ErrorHandlerInterface | ||
| { | ||
| /** | ||
| * @var \Magento\Framework\Logger\Monolog | ||
| */ | ||
| private $clientLogger; | ||
|
|
||
| /** | ||
| * @var \Magento\Framework\Logger\Monolog | ||
| */ | ||
| private $serverLogger; | ||
|
|
||
| /** | ||
| * @var array | ||
| */ | ||
| private $clientErrorCategories; | ||
|
|
||
| /** | ||
| * @var array | ||
| */ | ||
| private $serverErrorCategories; | ||
|
|
||
| /** | ||
| * @var \Magento\Framework\Logger\Monolog | ||
| */ | ||
| private $generalLogger; | ||
|
|
||
| /** | ||
| * ErrorHandler constructor. | ||
| * | ||
| * @param \Magento\Framework\Logger\Monolog $clientLogger | ||
novikor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param \Magento\Framework\Logger\Monolog $serverLogger | ||
| * @param \Magento\Framework\Logger\Monolog $generalLogger | ||
| * @param array $clientErrorCategories | ||
| * @param array $serverErrorCategories | ||
| * | ||
| * @SuppressWarnings(PHPMD.LongVariable) | ||
| */ | ||
| public function __construct( | ||
| \Magento\Framework\Logger\Monolog $clientLogger, | ||
| \Magento\Framework\Logger\Monolog $serverLogger, | ||
| \Magento\Framework\Logger\Monolog $generalLogger, | ||
| array $clientErrorCategories = [], | ||
| array $serverErrorCategories = [] | ||
| ) { | ||
| $this->clientLogger = $clientLogger; | ||
| $this->serverLogger = $serverLogger; | ||
| $this->generalLogger = $generalLogger; | ||
| $this->clientErrorCategories = $clientErrorCategories; | ||
| $this->serverErrorCategories = $serverErrorCategories; | ||
| } | ||
|
|
||
| /** | ||
| * Handle errors | ||
| * | ||
| * @param \GraphQL\Error\Error[] $errors | ||
| * @param callable $formatter | ||
| * | ||
| * @return array | ||
| */ | ||
| public function handle(array $errors, callable $formatter):array | ||
novikor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return array_map( | ||
| function (\GraphQL\Error\ClientAware $error) use ($formatter) { | ||
| $this->logError($error); | ||
|
|
||
| return $formatter($error); | ||
| }, | ||
| $errors | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param \GraphQL\Error\ClientAware $error | ||
| * | ||
| * @return boolean | ||
| */ | ||
| private function logError(\GraphQL\Error\ClientAware $error):bool | ||
vpodorozh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (in_array($error->getCategory(), $this->clientErrorCategories)) { | ||
novikor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return $this->clientLogger->error($error); | ||
| } elseif (in_array($error->getCategory(), $this->serverErrorCategories)) { | ||
| return $this->serverLogger->error($error); | ||
| } | ||
|
|
||
| return $this->generalLogger->error($error); | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
lib/internal/Magento/Framework/GraphQl/Query/ErrorHandlerInterface.php
This file contains hidden or 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,29 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\Framework\GraphQl\Query; | ||
|
|
||
| /** | ||
| * Interface ErrorHandlerInterface | ||
| * | ||
| * @package Magento\Framework\GraphQl\Query | ||
| */ | ||
| interface ErrorHandlerInterface | ||
| { | ||
| const SERVER_LOG_FILE = 'var/log/graphql/server/exception.log'; | ||
novikor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const CLIENT_LOG_FILE = 'var/log/graphql/client/exception.log'; | ||
| const GENERAL_LOG_FILE = 'var/log/graphql/exception.log'; | ||
| /** | ||
| * Handle errors | ||
| * | ||
| * @param \GraphQL\Error\Error[] $errors | ||
| * @param callable $formatter | ||
| * | ||
| * @return array | ||
| */ | ||
| public function handle(array $errors, callable $formatter):array; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.