[dancer-users] http_throw and Dancer2

Andrew Beverley andy at andybev.com
Thu Feb 4 10:34:43 EST 2021

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



More information about the dancer-users mailing list