I am using RestClient to make request to the thirdparty api. I am using the following code
try {
$payload = [
"email" => $user->email,
"groups" => [
$this->free_group_id
]
];
$api_result = $this->client->post('/api/subscribers', $payload);
$user->mailerlite_id = $api_result["data"]["id"];
$user->save();
} catch (RestClientException $e) {
Log::debug($e->getHttpCode());
Log::debug($e->getCode());
Log::debug($e->getMessage());
Log::debug($e->getTraceAsString());
$user->mailerlite_id = $api_result["data"]["id"];
$user->save();
}
But even if the post request succeeds, RestClientException arises
The response's httpcode is 201 (created) and I think this shouldn't be treated as exception.
Am I wrong? or Is this just a bug in the library?