Skip to content

Commit

Permalink
Bring back try/catch for 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Jan 2, 2016
1 parent 9e2d4a1 commit eaa42a5
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions src/Middleware/Debugbar.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<?php namespace Barryvdh\Debugbar\Middleware;

use Closure;
use Exception;
use Illuminate\Http\Request;
use Barryvdh\Debugbar\LaravelDebugbar;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;

class Debugbar {
class Debugbar
{
/**
* The App container
*
* @var Container
*/
protected $container;

/**
* The Exception Handler
* The DebugBar instance
*
* @var LaravelDebugbar
*/
Expand All @@ -15,27 +26,58 @@ class Debugbar {
/**
* Create a new middleware instance.
*
* @param Container $container
* @param LaravelDebugbar $debugbar
*/
public function __construct(LaravelDebugbar $debugbar)
public function __construct(Container $container, LaravelDebugbar $debugbar)
{
$this->container = $container;
$this->debugbar = $debugbar;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
try {
/** @var \Illuminate\Http\Response $response */
$response = $next($request);
} catch (Exception $e) {
$response = $this->handleException($request, $e);
}

// Modify the response to add the Debugbar
$this->debugbar->modifyResponse($request, $response);

return $response;

}

/**
* Handle the given exception.
*
* (Copy from Illuminate\Routing\Pipeline by Taylor Otwell)
*
* @param $passable
* @param Exception $e
* @return mixed
* @throws Exception
*/
protected function handleException($passable, Exception $e)
{
if (! $this->container->bound(ExceptionHandler::class) || ! $passable instanceof Request) {
throw $e;
}

$handler = $this->container->make(ExceptionHandler::class);

$handler->report($e);

return $handler->render($passable, $e);
}
}

0 comments on commit eaa42a5

Please sign in to comment.