StackTrace

19 views
Skip to first unread message

Miguel Prz

unread,
Jul 3, 2013, 3:21:48 PM7/3/13
to perl...@googlegroups.com
Hi, 

I have just installed Kelp 0.4001 and test the StackTrace config at development mode:
{
    middleware      => ['StackTrace'],
    middleware_init => {
        StackTrace => {
            force => 1
        }
    }
};

also I have a custom Response class which overloads the render_500 method:
sub render_500 {
    my $self = shift;
    $self->template('error/500');
}

If I generate an exception from a route, my custom error page is showed. I have to drop the render_500 method in order to get the StackTrace middleware.

What I like to have its:
  • at development mode, StackTrace support
  • at production mode, custom 500 error

How can I reach this?

Thanks!

Stefan Geneshky

unread,
Jul 3, 2013, 3:36:51 PM7/3/13
to perl...@googlegroups.com
With Kelp 0.4001 it is not recommended that you overload the render_500 method. Remove the custom render_500 method and you'll get to exactly what you need. In development mode each "die" will show StackTrace, in deployment mode a "die" will show your template views/error/500.tt.

If you explicitly call $self->res->render_500, then you'll get your custom template in all modes.

Stefan

Miguel Prz

unread,
Jul 3, 2013, 3:40:08 PM7/3/13
to perl...@googlegroups.com
Ok Sefan, where could I configure the path "views/error/500.tt." to my error template?

Stefan Geneshky

unread,
Jul 3, 2013, 3:43:17 PM7/3/13
to perl...@googlegroups.com
Just create a file called 500.tt and put it in views/error. If you already have it there, then you don't need to do anything else, but get rid of the custom render_500 method.

Miguel Prz

unread,
Jul 3, 2013, 3:54:22 PM7/3/13
to perl...@googlegroups.com
Ok, just tried it

It works as expected, but in my template, I didn't get the $error variable with the correct value, instead of that, I got "Internal Server Error".

I raised a exception in a route with:

die "my test exception";

and the 500 page prints "Internal server error". I have checked your Kelp::Response module, and I think you have to add the yellow marked code:

sub render_500 {
    my ( $self, $message ) = @_;
    if ( $self->app->mode ne 'deployment' ) {
        if ($message) {
            return $self->set_code(500)->render($message);
        }
        else {
            local $SIG{__DIE__};    # Silence StackTrace
            return $self->render_error( 500, $message );
        }
    }
    $self->render_error(500, $message);
}

Thanks, Stefan (sorry for the typo in your name in previous message)

Stefan Geneshky

unread,
Jul 3, 2013, 3:58:28 PM7/3/13
to perl...@googlegroups.com
Are you running in 'development' or 'deployment' ?

Miguel Prz

unread,
Jul 3, 2013, 4:02:01 PM7/3/13
to perl...@googlegroups.com
deployment:

%> plackup -E deployment -L Shotgun app.psgi

Stefan Geneshky

unread,
Jul 3, 2013, 4:03:52 PM7/3/13
to perl...@googlegroups.com
In deployment mode the 500 will not show the error. You don't want your app's users to see the die message in production, right?
The complete message will be, however, logged in the error.log.

Miguel Prz

unread,
Jul 3, 2013, 4:07:47 PM7/3/13
to perl...@googlegroups.com
I see your point, but if I don't want to show the error to the final user, I will drop the $error at the template, won't I? it's a custom template... the error information may be important (depends on the requirements of the app)

thanks

Stefan Geneshky

unread,
Jul 3, 2013, 4:15:23 PM7/3/13
to perl...@googlegroups.com
As a rule of thumb, when you have an exception (such as die), in development you'll get StackTrace, in deployment you'll get the custom 500 template. This covers 99% of the use cases. If you need something more customized, for example if you want to display error information important to the user, then add a render_info method in your custom Response class and make it show a template with the error.

Miguel Prz

unread,
Jul 3, 2013, 4:24:00 PM7/3/13
to perl...@googlegroups.com
ok, I have overloaded the render_500 method in the way I suggested in my previous message and it suits my needs.

Thanks!
Reply all
Reply to author
Forward
0 new messages