Here is my solution:
1.) Add in the composer.json "filp/whoops": "~1.0"
2.) Create in your app folder a "Infrastructure" folder. Then create a ExceptionHandler.php in this folder with following code:
<?php namespace App\Infrastructure;
use Exception;
use Illuminate\Http\Response;
use Psr\Log\LoggerInterface;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
class ExceptionHandler implements ExceptionHandlerContract {
/**
* The log implementation.
*
* @var \Psr\Log\LoggerInterface
*/
protected $log;
/**
* Create a new exception handler instance.
*
* @param \Psr\Log\LoggerInterface $log
* @return void
*/
public function __construct(LoggerInterface $log) {
$this->log = $log;
}
/**
* Report or log an exception.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e) {
$this->log->error((string) $e);
}
/**
* Render an exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Symfony\Component\HttpFoundation\Response
*/
public function render($request, Exception $e) {
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
return new Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
}
/**
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Exception $e
* @return void
*/
public function renderForConsole($output, Exception $e) {
$output->writeln((string) $e);
}
}
3.) Open up bootstrap/app.php change this:
$app->singleton(
'Illuminate\Contracts\Debug\ExceptionHandler',
'Illuminate\Foundation\Debug\ExceptionHandler'
);
to this:
$app->singleton(
'Illuminate\Contracts\Debug\ExceptionHandler',
'App\Infrastructure\ExceptionHandler',
'Illuminate\Foundation\Debug\ExceptionHandler'
);
Now you can customize your Exception Handler.
@Milon521 Thanks for your hint to the commit