Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

i tend to use

  try {
      ..... code
  } catch(PDOException $e){
    ..... return /  display error etc 
 }

But depends how your code with the issue is etc. With whoops have you got the Debug set to true so you get a great big orange page of errors that will display a more indepth reason etc?

Last updated 2 years ago.
0

simondavies said:

i tend to use

 try {
     ..... code
 } catch(PDOException $e){
   ..... return /  display error etc 
}

But depends how your code with the issue is etc. With whoops have you got the Debug set to true so you get a great big orange page of errors that will display a more indepth reason etc?

Normally that's how I'd catch exceptions, too. In this case, though, I'm not controlling the database connections (Laravel is) so don't want to have to wrap any of the Laravel code in try/catch blocks.

Re Whoops - yes, I have debug set to true as per default. The big orange page just shows the final exception as PDOException - that's what I'm trying to catch.

Last updated 2 years ago.
0

cools thanks for clarifying this, sorry. What are if any you getting within the error log?

could you try:

    Log:error( $exception->getMessage() );

Etc?

Last updated 2 years ago.
0

simondavies said:

cools thanks for clarifying this, sorry. What are if any you getting within the error log?

could you try:

   Log:error( $exception->getMessage() );

You missed a colon. ;-)

Etc?

There are two scenarios I'm trying to deal with here.

  1. If the database connection fails e.g. due to credential failure. I can simulate this by changing the password in app/config/database.php
  2. If the database connection fails e.g. if the MySQL server is completely unavailable. I can simulate this by stopping MAMP PRO and serving the app using Artisan.

I'm not sure why but in neither of those cases does anything get written to app/storage/logs/laravel.log. I thought it would be because of the event listener that writes errors the database, but I've commented the section and still nothing gets written to app/storage/logs/laravel.log

In fact, nothing is written there at all, unless the application is running without any problems. Exceptions are logged there if I make a mistake in my code, but "system" errors are not (e.g. MySQL connection problems as described above). That pretty much makes laravel.log useless.

Log::error calls do work, but again only if the database is running properly.

Last updated 2 years ago.
0

See if this helps - Using App::before to trap/catch PDOException Errors (http://www.laravel-tricks.com/tricks/using-appbefore-to-trapcatch-pdoexception-errors)

You can use App::before to catch a connection error

Last updated 2 years ago.
0

DragonI said:

See if this helps - Using App::before to trap/catch PDOException Errors (http://www.laravel-tricks.com/tricks/using-appbefore-to-trapcatch-pdoexception-errors)

You can use App::before to catch a connection error

@Dragonl it seems that you are not remembering why you use App:before when reading that link and your response to the comment.

Did you come up with an understanding and response to if there are any reason not to use App::error as a wrapper? Guess you are just registering an event listener that lives for eternity (until webserver is stopped) in either way...

Last updated 2 years ago.
0

anyone have a solution for this? I have the same issue.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.