Throwing response exceptions conditionally in Laravel 8.x

1 · Amit Merchant · Oct. 13, 2021, 4:01 p.m.
When you’re using Laravel’s Http client to make Http requests and something went wrong from the server-side, the server would return one of the error reponses such as 500 Internal Server Error, 502 Gateway Timeout, and so on. Now, Laravel already comes with a method called throw() that you can call on the response instance if there are any client or server errors. The method would throw an instance of Illuminate\Http\Client\RequestException in such a scenario. $response = Http::post('http://test...