mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
fix(graphql): dont report client errors (#961)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\GraphQL\Handler;
|
||||
|
||||
use Error as PhpError;
|
||||
use Exception;
|
||||
use GraphQL\Error\Error as GraphQLError;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Rebing\GraphQL\Error\AuthorizationError;
|
||||
use Rebing\GraphQL\Error\ValidationError;
|
||||
|
||||
class ErrorHandler
|
||||
{
|
||||
public static function handleErrors(array $errors, callable $formatter): array
|
||||
{
|
||||
$handler = app()->make(ExceptionHandler::class);
|
||||
|
||||
foreach ($errors as $error) {
|
||||
// Try to unwrap exception
|
||||
$error = $error->getPrevious() ?: $error;
|
||||
|
||||
// Don't report certain GraphQL errors
|
||||
if ($error instanceof ValidationError ||
|
||||
$error instanceof AuthorizationError ||
|
||||
$error instanceof GraphQLError ||
|
||||
! (
|
||||
$error instanceof Exception ||
|
||||
$error instanceof PhpError
|
||||
)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $error instanceof Exception) {
|
||||
$error = new Exception(
|
||||
$error->getMessage(),
|
||||
$error->getCode(),
|
||||
$error
|
||||
);
|
||||
}
|
||||
|
||||
$handler->report($error);
|
||||
}
|
||||
|
||||
return array_map($formatter, $errors);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -98,7 +98,7 @@ return [
|
||||
*
|
||||
* The default handler will pass exceptions to laravel Error Handling mechanism
|
||||
*/
|
||||
'errors_handler' => [Rebing\GraphQL\GraphQL::class, 'handleErrors'],
|
||||
'errors_handler' => [App\GraphQL\Handler\ErrorHandler::class, 'handleErrors'],
|
||||
|
||||
/*
|
||||
* Options to limit the query complexity and depth. See the doc
|
||||
|
||||
Reference in New Issue
Block a user