56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Exceptions;
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Throwable;
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
class Handler extends ExceptionHandler
|
|
{
|
|
/**
|
|
* The list of the inputs that are never flashed to the session on validation exceptions.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $dontFlash = [
|
|
'current_password',
|
|
'password',
|
|
'password_confirmation',
|
|
];
|
|
|
|
/**
|
|
* Register the exception handling callbacks for the application.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
// 404..
|
|
$this->renderable(function (NotFoundHttpException $e, $request) {
|
|
if ($request->is('api/*')) {
|
|
return response()->noContent(404);
|
|
}
|
|
});
|
|
|
|
$this->reportable(function (Throwable $e) {
|
|
$statusCode = $e instanceof HttpException ? $e->getStatusCode() : 500;
|
|
|
|
// only real server errors
|
|
if ($statusCode < 500) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
warn(
|
|
message: get_class($e),
|
|
content: $e->getMessage(),
|
|
where: $e->getFile() . ':' . $e->getLine(),
|
|
notes: substr($e->getTraceAsString(), 0, 65000),
|
|
);
|
|
} catch (Throwable $ignored) {
|
|
// logging must never crash the app
|
|
}
|
|
});
|
|
}
|
|
}
|