[dancer-users] http_throw and Dancer2

Andrew Beverley andy at andybev.com
Sat Feb 6 14:53:16 EST 2021


On Sat, 6 Feb 2021 09:34:23 -0500 Paul Clements wrote:
> On Thu, Feb 4, 2021 at 9:06 AM Andrew Beverley <andy at andybev.com> wrote:
> > The idea is that you throw an exception anywhere:
> >
> >   error __x"Invalid email address: {email}", email => $email
> >
> > Then it ends up in the fatal_handler to return the custom response
> 
> One question:
> This is all working great and I'm getting the correct HTTP responses,
> but (at least in development mode) I'm also getting a stack trace
> logged for every "error" call. Is there maybe a way to suppress the
> stack trace for expected exceptions? Ideally, I'd like to see stack
> traces for 500 errors, but not 4xx ones.

Yes, you just need to change the run mode:

https://metacpan.org/pod/Log::Report#Run-modes

The run mode defines both what is reported and whether there is a stack
trace, as per the table of run modes in this section:

https://metacpan.org/pod/Log::Report::Dispatcher#Processing-the-message

You should just be able to define it in your config (better in
environment/ so that you can switch between them), something like this:

engines:
  logger:
    LogReport:
      app_name: MyApp
      dispatchers:
        default:
          type: SYSLOG
          identity: MyApp
          facility: local0
          flags: "pid ndelay nowait"
          mode: NORMAL


More information about the dancer-users mailing list