2026-06-23 10:10:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
|
|
|
|
|
2026-07-18 09:09:04 +00:00
|
|
|
use Illuminate\Auth\AuthenticationException;
|
2026-06-23 10:10:28 +00:00
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
2026-07-18 09:09:04 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2026-06-23 10:10:28 +00:00
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
$this->reportable(function (Throwable $e) {
|
|
|
|
|
//
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-07-18 09:09:04 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This app is a pure JSON API (SPA frontend, no server-rendered login route),
|
|
|
|
|
* so unauthenticated requests always get a 401 JSON response instead of
|
|
|
|
|
* Laravel's default redirect-to-login fallback.
|
|
|
|
|
*/
|
|
|
|
|
protected function unauthenticated($request, AuthenticationException $exception): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
return response()->json(['message' => $exception->getMessage()], 401);
|
|
|
|
|
}
|
2026-06-23 10:10:28 +00:00
|
|
|
}
|