in reply to CGI::Application::Plugin::DBH connect error handling
I put something like this in my instance script (and maybe in my application models, also):
use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { set_message( sub { my $msg = shift; # message for development server #print "<h3>Server Error!</h3><pre>$msg</pre>"; # message for production server print "<h3>Server Error!</h3><p>Please try again later</p>"; }); }
Then I wrap all my database stuff with eval:
eval { $db1 = DBI->connect( $CFG{'DB_DSN'}, $CFG{'DB_USER'}, $CFG{'DB_PASS'}, {RaiseError => 1, AutoCommit => 1, }, ); }; if ($@) { die "Database error: failed to connect.\n"; }
This basically allows me to trap any DB related errors, and avoid sending too much information to the browser, unless I'm in "debug mode".
|
---|