Less detailed debugging screen in Catalyst?

at my server stage, I would like to activate debugging so that clients can find errors for themselves before the application goes to the production server.

but I only need the first part of the message, not the request or session data.

For example: It is not possible to display the template "templates / home.tt2: file error - templates / inc / heater: not found".

The message is enough for me and for my client to see that the "header" call has a spelling error.

The request has a lot of irrelevant information for the client, but there is also MUCH internal information that must be hidden all the time!

Hello

+6
source share
3 answers

You want to override the Catalyst dump_these method. This returns a list of things displayed on the Catalyst error debugging page.

The default implementation looks like this:

 sub dump_these { my $c = shift; [ Request => $c->req ], [ Response => $c->res ], [ Stash => $c->stash ], [ Config => $c->config ]; } 

but you can make it more restrictive, for example

 sub dump_these { my $c = shift; return [ Apology => "We're sorry that you encountered a problem" ], [ Response => substr($c->res->body, 0, 512) ]; } 

In the main application module, you define dump_these - the one where you use Catalyst .

+3
source

I had a similar problem that I solved by overriding the Catalyst log_request_parameters method.

Something like this (as @mob said, put it in your main module):

 sub log_request_parameters { my $c = shift; my %all_params = @_; my $copy = Clone::clone(\%all_params); # don't change the 'real' request params # Then, do anything you want to only print what matters to you, # for example, to hide some POST parameters: my $body = $copy->{body} || {}; foreach my $key (keys %$body) { $body->{$key} = '****' if $key =~ /password/; } return $c->SUPER::log_request_parameters( %$copy ); } 

But you can also just go back at the beginning if you don't want to display the GET / POST parameters.

+1
source

Well, I didn’t think of a more obvious solution, in your case: you could just set your log level to something more than debug , which would prevent these debug logs from showing up, but would support error logs:

 # (or a similar condition to check you are not on the production server) if ( !__PACKAGE__->config->{dev} ) { __PACKAGE__->log->levels( 'warn', 'error', 'fatal' ) if ref __PACKAGE__->log; } 
0
source

Source: https://habr.com/ru/post/954700/


All Articles