1
<?php
2

3
namespace Nuwave\Lighthouse\Execution;
4

5
use Closure;
6
use GraphQL\Error\Error;
7
use Illuminate\Contracts\Debug\ExceptionHandler;
8

9
/**
10
 * Report errors through the default exception handler configured in Laravel.
11
 */
12
class ReportingErrorHandler implements ErrorHandler
13
{
14
    /**
15
     * @var \Illuminate\Contracts\Debug\ExceptionHandler
16
     */
17
    protected $exceptionHandler;
18

19 1
    public function __construct(ExceptionHandler $exceptionHandler)
20
    {
21 1
        $this->exceptionHandler = $exceptionHandler;
22
    }
23

24 1
    public function __invoke(?Error $error, Closure $next): ?array
25
    {
26 1
        if ($error === null) {
27 0
            return $next(null);
28
        }
29

30
        // Client-safe errors are assumed to be something that a client can handle
31
        // or is expected to happen, e.g. wrong syntax, authentication or validation
32 1
        if ($error->isClientSafe()) {
33 1
            return $next($error);
34
        }
35

36 1
        $previous = $error->getPrevious();
37 1
        if ($previous !== null) {
38
            // @phpstan-ignore-next-line Laravel versions prior to 7 are limited to accepting \Exception
39 1
            $this->exceptionHandler->report($previous);
40
        }
41

42 1
        return $next($error);
43
    }
44
}

Read our documentation on viewing source code .

Loading