[dancer-users] http_throw and Dancer2

Paul Clements paul.clements at us.sios.com
Thu Feb 4 13:06:55 EST 2021


On Thu, Feb 4, 2021 at 5:34 AM Andrew Beverley <andy at andybev.com> wrote:
>
> On Wed, 3 Feb 2021 17:49:05 -0500 Paul Clements wrote:
> > I've been trying for a while now to figure out the best way to handle
> > exceptions with Dancer2.
>
> Do you mean "expected" or "unexpected" exceptions? I.e. exceptions you
> use for application flow, or ones that are as a result of internal bugs.
>
> > Basically, it appears that Dancer2 wants to intercept any exception
> > and rethrow it as 500 (Internal Server Error) without some hacky hook
> > code to intercept the exception and re-apply it later.
> >
> > Has anyone dealt with this issue? Is there a better way to handle this
> > (some middleware or config option)?
>
> I wrote a plugin to try and sew together exceptions, both expected and
> unexpected, along with general user messages and logging. For any
> unexpected exception in a production application, the plugin will catch
> it, forward the user to a "safe" page in the application, and add a
> user-friendly message to the session. The actual exception with
> stacktrace is (optionally) reported to syslog.
>
> For expected exceptions, a special "process" keyword is added, which
> catches errors and adds them as messages to the session.
>
> It works well for me and is in production on several sites.
>
> Maybe I have misunderstood your requirements, but here's the plugin
> anyway:
>
> https://metacpan.org/pod/Dancer2::Plugin::LogReport
>
> Andy


More information about the dancer-users mailing list