1
0
Fork 0

Update exceptions handler

This commit is contained in:
Daniel Supernault 2021-05-27 23:06:47 -06:00
parent 178ed63d0a
commit 7e0be15404
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 46 additions and 45 deletions

View File

@ -4,55 +4,56 @@ namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable; use Throwable;
use League\OAuth2\Server\Exception\OAuthServerException;
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
{ {
/** /**
* A list of the exception types that are not reported. * A list of the exception types that are not reported.
* *
* @var array * @var array
*/ */
protected $dontReport = [ protected $dontReport = [
// OAuthServerException::class
]; ];
/** /**
* A list of the inputs that are never flashed for validation exceptions. * A list of the inputs that are never flashed for validation exceptions.
* *
* @var array * @var array
*/ */
protected $dontFlash = [ protected $dontFlash = [
'password', 'password',
'password_confirmation', 'password_confirmation',
]; ];
/** /**
* Report or log an exception. * Report or log an exception.
* *
* @param \Exception $exception * @param \Exception $exception
* *
* @return void * @return void
*/ */
public function report(Throwable $exception) public function report(Throwable $exception)
{ {
parent::report($exception); parent::report($exception);
} }
/** /**
* Render an exception into an HTTP response. * Render an exception into an HTTP response.
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Exception $exception * @param \Exception $exception
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function render($request, Throwable $exception) public function render($request, Throwable $exception)
{ {
if ($request->wantsJson()) if ($request->wantsJson())
return response()->json( return response()->json(
['error' => $exception->getMessage()], ['error' => $exception->getMessage()],
method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500 method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
); );
return parent::render($request, $exception); return parent::render($request, $exception);
} }
} }