vendredi 1 septembre 2017

Handling Client Errors exceptions on GuzzleHttp

im trying to handdle request status code, basically checking if the status is 200, in case that it isnt handle it. Im using a package called "GuzzleHttp\Client", when there is a 404 it gives me a error:

Client error: `GET https://api.someurl---` resulted in a `404 Not Found` response:
{"generated_at":"2017-09-01T16:59:25+00:00","schema":"","message":"No events scheduled for this date."}

But than in the screen is displayed in a format that i want to change, so im trying to catch and give a different output on the view. But is not working, it stills gives me the red screen error.

try {
            $client = new \GuzzleHttp\Client();
            $request = $client->request('GET', $url);
            $status = $request->getStatusCode();
            if($status == 200){
                return $status;

            }else{

                throw new \Exception('Failed');
            }

        } catch (\GuzzleHttp\Exception\ConnectException $e) {
            //Catch errors
            return $e->getStatusCode();

        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire