2018-04-15 23:56:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
2020-05-29 07:01:32 +00:00
|
|
|
use Throwable;
|
2021-05-28 05:06:47 +00:00
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
2021-06-02 03:18:02 +00:00
|
|
|
use Zttp\ConnectionException;
|
2018-04-15 23:56:48 +00:00
|
|
|
|
|
|
|
class Handler extends ExceptionHandler
|
|
|
|
{
|
2021-05-28 05:06:47 +00:00
|
|
|
/**
|
|
|
|
* A list of the exception types that are not reported.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dontReport = [
|
2021-06-02 03:18:02 +00:00
|
|
|
OAuthServerException::class,
|
|
|
|
ConnectionException::class
|
2021-05-28 05:06:47 +00:00
|
|
|
];
|
2018-04-15 23:56:48 +00:00
|
|
|
|
2021-05-28 05:06:47 +00:00
|
|
|
/**
|
|
|
|
* A list of the inputs that are never flashed for validation exceptions.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dontFlash = [
|
|
|
|
'password',
|
|
|
|
'password_confirmation',
|
|
|
|
];
|
2018-04-15 23:56:48 +00:00
|
|
|
|
2021-05-28 05:06:47 +00:00
|
|
|
/**
|
|
|
|
* Report or log an exception.
|
|
|
|
*
|
|
|
|
* @param \Exception $exception
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function report(Throwable $exception)
|
|
|
|
{
|
|
|
|
parent::report($exception);
|
|
|
|
}
|
2018-04-15 23:56:48 +00:00
|
|
|
|
2021-12-31 07:58:16 +00:00
|
|
|
/**
|
|
|
|
* Register the exception handling callbacks for the application.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
$this->reportable(function (\BadMethodCallException $e) {
|
|
|
|
return app()->environment() !== 'production';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-28 05:06:47 +00:00
|
|
|
/**
|
|
|
|
* Render an exception into an HTTP response.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Exception $exception
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function render($request, Throwable $exception)
|
|
|
|
{
|
|
|
|
if ($request->wantsJson())
|
|
|
|
return response()->json(
|
|
|
|
['error' => $exception->getMessage()],
|
|
|
|
method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
|
|
|
|
);
|
|
|
|
return parent::render($request, $exception);
|
|
|
|
}
|
2018-04-15 23:56:48 +00:00
|
|
|
}
|