per ho risolto così.
invio di 'Accept':'application/json' nell'header della chiamata.
poi:
codice:
namespace App\Exceptions;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler {
..............................................
/**
* @param \Illuminate\Http\Request $request
* @param AuthenticationException $exception
* @return \Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/
protected function unauthenticated($request, AuthenticationException $exception) {
return response()->json([
'res' => 'ko',
'message' => 'Non sei autorizzato a vedere questa risorsa!'
]);
}
}
ho aggiunto un metodo.
sembra funzionare.