0

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?

2
  • 1
    Indeed, 201 is a success code and should probably not raise an exception. Commented Apr 17, 2024 at 18:44
  • What's the debug output? Commented Apr 17, 2024 at 18:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.