dimanche 4 octobre 2015

Laravel handle nested exceptions and keep going

I have a question regarding PHP's way to handle exceptions and Laravel 5. Here's a snippet of what I'm trying to accomplish

try
{
//set up webservices
saveData();
} catch(exception $e)
{
Log:error('stuff went bananas')
}

saveData(){
//record stuff through DB with eloquent
//in case some data is missing connect to a second DB
try
{
connect()
query to get data
}catch(exception $e)
{
//log error again
}

In other words, I'm calling webservices that receive data. I'm then inserting these into my own DB inside the Model. At this stage I'm trying to see if I know the user ID that I just received. In case I don't I have to connect to a second database to request that same user.

There are two issues though

  • the second database I'm trying to connect isn't likely to be up
  • it will often not hold the information I need (I have to try again the next day)

There's nothing I can do against these issues. But what I want is for my code to try and connect, and in case it fails, log the errors and keep moving inserting the data.

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire