mailerlite / mailerlite-api-v2-php-sdk

Official PHP wrapper for MailerLite Classic HTTP API v2
https://developers-classic.mailerlite.com/docs
MIT License
80 stars 44 forks source link

Library doesn't catch all errors - error 500 in php because of that #73

Closed ShinJii89 closed 1 year ago

ShinJii89 commented 2 years ago

Hi, We have some clients which random has errors like "Too many requests" but there's error 500 in php even if we have in code try catch....

try {
$mailerliteClient = new \MailerLiteApi\MailerLite($mailerlite['mailerlite_key']);
  $data_contact = array('email' => $userdata['email'], 'name' => $userdata['firstname'], 'resubscribe' => true);
                                    $ml = explode('|', $fast_selling['mailerlite']);
 foreach ($ml as $mlk) {
                                        if (stripos($mlk, 'aps_') !== false) { //after pay subscribe
                                            $aps = explode('_', $mlk);
                                            $aps_id = $aps[1];
                                            $addedSubscriber = $mailerliteClient->groups()->addSubscriber($aps_id, $data_contact);
                                        }

                                        if (stripos($mlk, 'apu_') !== false) { // after pay unsubscribe
                                            $apu = explode('_', $mlk);
                                            $apu_id = $apu[1];
                                            $subscribers = $mailerliteClient->subscribers()->search($data_contact['email']); // returns array of subscriber objects that match query
                                            $s_id = $subscribers[0]->id;
                                            if (!empty($s_id)) {
                                                $groupId = $apu_id;
                                                $subscriberId = $s_id;
                                                $mailerliteClient->groups()->removeSubscriber($groupId, $subscriberId);
                                            }
                                        }
                                    }

} catch (\MailerLiteApi\Exceptions\MailerLiteSdkException $e) {

} catch (\Exception $e) {
}

Can you fix that as fast as it's possible?

ShinJii89 commented 2 years ago

anyone?... @johnkelesidis

johnkelesidis commented 2 years ago

where are you getting a 500 error? on the addSubscriber, search or removeSubscriber calls? also, are you targeting mailerlite or mailerlite classic? (if you are not sure what's the size of your api key?)

ShinJii89 commented 2 years ago

where are you getting a 500 error? on the addSubscriber, search or removeSubscriber calls? also, are you targeting mailerlite or mailerlite classic? (if you are not sure what's the size of your api key?)

We had (which we know) 2 clients with that problem and I can see they have new mailerlite api key.

I can't reproduce now 500 in PHP but it was something with ->groups() (doesn't matter if add,remove etc.)

Now I have also fresh "error" with too many requests:

  try {
 $mailerliteClient = new \MailerLiteApi\MailerLite($mailerlite_data['mailerlite_key']);
                    $mailerlite_groupsApi = $mailerliteClient->groups();
                    $mailerlite_groups = $mailerlite_groupsApi->orderBy('name', 'ASC')->get(); // returns array of groups
                   if (isset($mailerlite_groups[0]->error)) {
echo $mailerlite_groups[0]->error->message;
}
  } catch (\MailerLiteApi\Exceptions\MailerLiteSdkException $e) {
                                    echo $e->getMessage();
                                } catch (\Exception $e) {
                                    echo $e->getMessage();
                                }

Until I have if (isset($mailerlite_groups[0]->error)) { - I can see error "too many requests" but If I delete that - there's nothing, try catch doesn't work and not load any lists and any errors... why? @johnkelesidis

ShinJii89 commented 1 year ago

come on people, why are you so ignorant of this plugin?

johnkelesidis commented 1 year ago

@ShinJii89 we released some updates regarding this, can you give it another shot?

ShinJii89 commented 1 year ago

@johnkelesidis you talk about to small limit and error "Too many requests" or about try catch doesn't work? :D

johnkelesidis commented 1 year ago

the too many requests one, I'm afraid we can't replicate the 500 error

ShinJii89 commented 1 year ago

@johnkelesidis I looked at this now and it looks like there's no "too many requests" anymore... I hope :))) thanks!