>被截断的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中文网其他相关文章!