Created
June 6, 2019 07:25
-
-
Save thephucit/3fae2d36bf6c1ae36a850460e85629e0 to your computer and use it in GitHub Desktop.
customize error for graphql
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
| <?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