>被截斷的HTTP客戶端異常沮喪,掩蓋了錯誤報告或哨兵中關鍵的調試信息嗎? Laravel對HTTP響應的默認截斷可能會隱藏有關請求失敗的重要線索。
在Laravel 11.35中解決了這個問題! 兩種新方法提供了對異常截斷的精確控制。 只需將它們添加到您的>: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(), // ... ]); }
特別感謝史蒂夫·鮑曼(Steve Bauman)(拉申請#53734)在Laravel 11.35.0!
以上是自定義HTTP客戶端請求異常的截斷的詳細內容。更多資訊請關注PHP中文網其他相關文章!