Skip to content

Instantly share code, notes, and snippets.

@thephucit
Created June 6, 2019 07:25
Show Gist options
  • Select an option

  • Save thephucit/3fae2d36bf6c1ae36a850460e85629e0 to your computer and use it in GitHub Desktop.

Select an option

Save thephucit/3fae2d36bf6c1ae36a850460e85629e0 to your computer and use it in GitHub Desktop.
customize error for graphql
<?php namespace Name\Graphql\Classes;
use GraphQL\Error\Error;
use Rebing\GraphQL\Error\ValidationError;
use Rebing\GraphQL\GraphQL;
class ErrorCatch extends GraphQL
{
public static function formatError(Error $e)
{
$error = ['message' => $e->getMessage()];
$previous = $e->getPrevious();
if ($previous && $previous instanceof ValidationError) {
$error['validation'] = $previous->getValidatorMessages();
}
return $error;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment