You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

58 lines
1.7 KiB

<?php
namespace App\Utilities\Exceptions;
use Throwable;
use ReflectionClass;
use ReflectionMethod;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
public function report(Throwable $exception)
{
// A trick that I took from Laravel macroable trait
$methods = (new ReflectionClass($exception))->getMethods(
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED
);
$result = [];
foreach ($methods as $method) {
// invoke the method so we can collect the result of execution it
$result[$method->name] = $method->invoke($exception);
}
// Clear the unnecessary method
unset($result['getTrace']);
unset($result['__toString']);
// clear the null values then encode it as json
// so we can decode it as an object in the Monolog Processor
$result = json_encode(array_filter($result));
return Log::emergency($result);
}
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
}