-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from markusguenther/feature/localized-exceptions
FEATURE: Use custom transformer for flow exceptions
- Loading branch information
Showing
11 changed files
with
603 additions
and
29 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
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flowpack\Media\Ui\Transform; | ||
|
||
use GraphQL\Error\Error; | ||
use GraphQL\Executor\ExecutionResult; | ||
use GraphQLTools\Transforms\Transform; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Log\ThrowableStorageInterface; | ||
|
||
/** | ||
* This transform is used to convert exceptions to errors in the GraphQL response. | ||
* To be able to localize error messages we extend the FlowErrorTransform from the t3n.GraphQL package. | ||
*/ | ||
class FlowErrorTransform extends \t3n\GraphQL\Transform\FlowErrorTransform | ||
{ | ||
public function transformResult(ExecutionResult $result): ExecutionResult | ||
{ | ||
$result->errors = array_map(function (Error $error) { | ||
$previousError = $error->getPrevious(); | ||
if (!$previousError instanceof Error) { | ||
$message = $this->throwableStorage->logThrowable($previousError); | ||
|
||
if (!$this->includeExceptionMessageInOutput) { | ||
$message = preg_replace('/.* - See also: (.+)\.txt$/s', 'Internal error ($1)', $message); | ||
} | ||
|
||
$errorExtendedInformation = $error->getExtensions(); | ||
$errorExtendedInformation['errorCode'] = $previousError->getCode(); | ||
|
||
return new Error( | ||
$message, | ||
$error->getNodes(), | ||
$error->getSource(), | ||
$error->getPositions(), | ||
$error->getPath(), | ||
$previousError, | ||
$errorExtendedInformation | ||
); | ||
} | ||
|
||
return $error; | ||
}, $result->errors); | ||
|
||
return $result; | ||
} | ||
} |
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
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
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
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
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
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
25 changes: 16 additions & 9 deletions
25
Resources/Private/JavaScript/media-module/src/core/CreateErrorHandler.ts
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
Oops, something went wrong.