-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Use custom transformer for flow exceptions
The t3n GraphQL package includes a transformer that bypasses Flow Framework exceptions in GraphQL error handling. The error currently lacks the exception code as part of the information. By including this code (often a timestamp), we can render custom error messages in the backend and support localization.
- Loading branch information
1 parent
f236534
commit f100b66
Showing
7 changed files
with
91 additions
and
22 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,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
22 changes: 13 additions & 9 deletions
22
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.