0

I have a site that uses a lot of apis to other places. I've been using curl and a bunch of if(!something) to do it, but I want to switch to a more robust solution, so I'm trying to use guzzle. But I am not sure how to handle the exceptions.

I did this..

class Api {
    ...
   function request ($params) {
      tries = 0;
      while (tries < 3) {
         try {$resp = $client->request(params);
       } catch (\GuzzleHttpException $e)  {
          some stuff
          if ($tries > 2) {
            LOG error( failure info);
            return [];
          }
         sleep 1;
         ++$tries;
        }
     break;
   }
   return $resp;
}

So my question is how do I better identify the errors here. I want to know why it failed... connection, 500, 404, timeout, etc. Don't know how to "stack" Exceptions. Guzzle has many different except types. (+ I'm on php 8 so errors should be exceptions too I think. ) Some guidance??

0 Answers0