Masalah ini diselesaikan dalam Laravel 11.35! Dua kaedah baru menawarkan kawalan yang tepat ke atas pemotongan pengecualian. Cukup tambahkannya ke
anda: bootstrap/app.php
// bootstrap/app.php use Illuminate\Http\Client\RequestException; return Application::configure(basePath: dirname(__DIR__)) // ... ->withExceptions(function (Exceptions $exceptions) { $exceptions->dontTruncateRequestExceptions(); // Completely disable truncation // Or... $exceptions->truncateRequestExceptionsAt(260); // Set a custom truncation length })->create();
try { $response = Http::throws()->get('https://api.example.com/some-error'); // ... } catch (\Illuminate\Http\Client\RequestException $e) { Log::error('HTTP Error', [ 'message' => $e->getMessage(), // Truncated or not, depending on your setting 'response' => $e->response->json(), 'status' => $e->response->status(), // ... ]); }
terima kasih khas kepada Steve Bauman (Tarik Permintaan #53734) untuk peningkatan berharga ini dalam Laravel 11.35.0!
Atas ialah kandungan terperinci Sesuaikan pemotongan pengecualian permintaan klien HTTP. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!