GraphQLBundle
GraphQLBundle copied to clipboard
ExceptionConverter doesn't respect converted error message
I try to convert exceptions with ExceptionConverterInterface like this:
class DomainExceptionConverter implements ExceptionConverterInterface
{
public function convertException(Throwable $exception): Throwable
{
if ($exception instanceof NotEnabledTransitionException) {
$message = "";
foreach ($exception->getTransitionBlockerList() as $blocker) {
$message .= $blocker->getMessage() . "; ";
}
$message = rtrim($message, "; ");
return new PermissionDeniedError($message);
}
}
However the resulting message in GraphQL error comes from original exception and not from converted one. It seems like a defenitely not expected behavior / bug.
It comes from Error\ErrorHandler:
private function treatExceptions(array $errors, bool $throwRawException): array
{
//...
// recreate a error with converted exception
$errorWithConvertedException = new GraphQLError(
$error->getMessage(), // Here the original message is passed
$error->nodes,
$error->getSource(),
$error->getPositions(),
$error->path,
$rawException
);
// ...
}
I suppose it should look like:
$errorWithConvertedException = new GraphQLError(
$rawException && $rawException->getMessage() ?? $error->getMessage(),
// ...
);
I've actually do not understand at all why the converted message is treated as 'previous' and not the main error.
| Q | A |
|---|---|
| Bug report? | yes |
| Feature request? | no |
| BC Break report? | no |
| RFC? | no |
| Version/Branch | 0.13.2 |