Hi again, have you tried the documented way to access the DBI error, by using a hook?

database_error

Called when a database error is raised by DBI. Receives two parameters: the error message being returned by DBI, and the database handle in question.

(See https://metacpan.org/pod/Dancer2::Plugin::Database#HOOKS)

Edit: I spun up a test:

Create a DB with no tables:

$ sqlite3 test.db

In config.yml:

plugins: Database: driver: SQLite database: 'test.db'

app.psgi:

#!/usr/bin/env perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use TestApp; TestApp->to_app;

TestApp.pm:

package TestApp; use Dancer2; use Dancer2::Plugin::Database; hook 'database_error' => sub { my $err = shift; warn "\nThe DB error: `$err`"; }; get '/' => sub { eval { database->quick_insert('no_such_table', { foo => 'bar' }) } +; 'Hello, world'; }; 1;

Log output:

HTTP::Server::PSGI: Accepting connections at http://0:5000/ [TestApp:4783] core @2018-09-23 09:52:38> looking for get / in /home/n +ick/perl5/perlbrew/perls/perl-5.28.0/lib/site_perl/5.28.0/Dancer2/Cor +e/App.pm l. 36 [TestApp:4783] core @2018-09-23 09:52:38> Entering hook core.app.befor +e_request in (eval 305) l. 1 [TestApp:4783] debug @2018-09-23 09:52:38> Adding sqlite_unicode to DB +I connection params to enable UTF-8 support in /home/nick/perl5/perlb +rew/perls/perl-5.28.0/lib/site_perl/5.28.0/Dancer2/Plugin.pm l. 543 [TestApp:4783] core @2018-09-23 09:52:38> Entering hook plugin.databas +e.database_connected in (eval 305) l. 1 [TestApp:4783] core @2018-09-23 09:52:38> Entering hook plugin.databas +e.database_error in (eval 305) l. 1 The DB error: `DBD::SQLite::db do failed: no such table: no_such_table +` at /home/nick/dev/TestApp/bin/../lib/TestApp.pm line 11. DBD::SQLite::db do failed: no such table: no_such_table at /home/nick/ +perl5/perlbrew/perls/perl-5.28.0/lib/site_perl/5.28.0/Dancer/Plugin/D +atabase/Core/Handle.pm line 310. ...
(Note that the DB error is also printed to the log by default; you should be able to see that in your log and only need to use the hook if further processing is desired.)

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Dancer2::Plugin::Database and database errors (hook database_error) by 1nickt
in thread Dancer2::Plugin::Database and database errors by lee_crites

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.