@nicekiwi Because that’s the message from the exception. Not the response of the HTTP request.
The getMessage method is for returning a string value describing the exception that was thrown. Which is what you’re getting.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
[Laravel 9]
I'm using Illuminate\Support\Facades\Http::get to query an external API, and upon an error it returns a JSON error response.
But when catching exceptions and calling $exception->getMessage() instead of a JSON string, I get a text message describing the error before the JSON.
e.g.
HTTP request returned status code 403: {"error":{"message":"Error message detials","error_code":null}}
I've checked via curl and the API does only return the JSON part. So why is Laravel adding the string HTTP request returned status code 403: and how do I stop it doing so?
@nicekiwi Because that’s the message from the exception. Not the response of the HTTP request.
The getMessage method is for returning a string value describing the exception that was thrown. Which is what you’re getting.
Please or to participate in this conversation.