how can I add an additional exception handler at a different location?
I tried this:
<?php namespace Modules\Gewora\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Session\TokenMismatchException;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
'Symfony\Component\HttpKernel\Exception\HttpException'
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
dd('Test1');
if($e instanceof TokenMismatchException) {
dd('Test2');
}
return parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($this->isHttpException($e))
{
return $this->renderHttpException($e);
}
else
{
return parent::render($request, $e);
}
}
}
But it does not catch the exception, it does not even go into the report method even though the file has been loaded correctly. What am I doing wrong?
Is there a way to do that without touching any of the original files? The system should be module based and therefore should not touch the original files, just to catch an Exception.
Ah I see, thanks. There is really no way to handle a simple exception without touching the main files? Can't really believe that. Maybe someone else can come up with a hint for that.
Yeah, but I hoped that I can avoid that, especially because I can't (technically I can, but i would rather play with spiders. Eww, spiders) do that cause a TokenMismatchException can be thrown at so many places. Will wait a bit, maybe someone has another idea. In L4 this was not a big deal cause of App::error() :/
What if you make a service provider for your module and erase this binding :
public function register()
{
$this->app->singleton(
'Illuminate\Contracts\Debug\ExceptionHandler',
'Modules\Gewora\Exceptions'
);
}
Dont know if it works but I think it is worth trying.
Of course if you want to keep the original exception handler functionalities you have to extends it (App\Exceptions\Handler) and call the parent methods in your custom exception handler.
Yeah I use a modules package which handles the registration of the ServiceProvider in the corresponding module. The ServiceProvider is registered for sure.