Skip to content

Instantly share code, notes, and snippets.

@adampatterson
Created October 18, 2017 00:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampatterson/1c01aec54ebce7632bddd9e9e8566a65 to your computer and use it in GitHub Desktop.
Save adampatterson/1c01aec54ebce7632bddd9e9e8566a65 to your computer and use it in GitHub Desktop.
Whoops PHP Storm Config
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
*
* @return void
*/
public function report(Exception $exception)
{
if ( ! config('app.debug')) {
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}
}
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if (config('app.debug') && app()->environment() != 'production') {
return $this->handleWhoopsies($request, $exception);
}
return parent::render($request, $exception);
}
/**
* @param $request
* @param Exception $exception
*
* @return \Illuminate\Http\Response|mixed
*/
protected function handleWhoopsies($request, Exception $exception)
{
if ($request->ajax()) {
return $this->renderJsonExceptionWithWhoops();
} else {
return $this->renderExceptionWithWhoops($exception);
}
}
/**
* @return mixed
*/
protected function renderJsonExceptionWithWhoops()
{
$whoops = new \Whoops\Run;
return $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
}
/**
* Render an exception using Whoops.
*
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
protected function renderExceptionWithWhoops(Exception $exception)
{
$whoops = new \Whoops\Run;
$handler = new \Whoops\Handler\PrettyPageHandler();
$handler->setEditor('phpstorm');
$whoops->pushHandler($handler);
return new \Illuminate\Http\Response($whoops->handleException($exception), $exception->getStatusCode(),
$exception->getHeaders());
}
}
@shiroamada
Copy link

somehow I added this line, my ValidationException not working well.
inside the $dontReport array, I already added ValidationException but still the same.
I test with simple field with required rule. It keep throwing the exception

Illuminate \ Validation \ ValidationException
The given data was invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment