Working with Laravel’s https://laravel.com/docs/8.x/http-client, there might be the scenario where the outgoing HTTP requests that you’re making might return responses with different status codes. Among all the https://developer.mozilla.org/en-US/docs/Web/HTTP/Status, two response codes are sent when the user is not authorized to access the resources for two different reasons. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 — The status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 — The status code indicates that the server understands the request but refuses to authorize it.
Now, the Laravel HTTP client lets you check these status codes through the status() method that you can call on the HTTP response like so.