Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less verbose debug screen in Catalyst?

in my stage server I would like to activate the debug so the clients can find errors for themselves before the app goes to the production server.

BUT I only want the first part of the message, not the Request, or the Session Data.

For example: Couldn't render 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 is misspelled.

The Request has a lot of irrelevant information for the client, but also has A LOT of internal developing information that should be hidden all the time!!

Regards

like image 945
Nacho B Avatar asked Sep 26 '13 16:09

Nacho B


2 Answers

What you want is to override Catalyst's dump_these method. This returns a list of things to display on Catalyst's error debugging page.

The default implementation looks like:

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) ];
}

You would define dump_these in your app's main module -- the one where you use Catalyst.

like image 192
mob Avatar answered Oct 28 '22 01:10

mob


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

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 could also simply return at the beginning, if you don't want any GET/POST parameters displayed.

like image 24
Yann Dìnendal Avatar answered Oct 28 '22 01:10

Yann Dìnendal