Skip to content

Instantly share code, notes, and snippets.

@LoonyPandora
Created September 13, 2011 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoonyPandora/1213906 to your computer and use it in GitHub Desktop.
Save LoonyPandora/1213906 to your computer and use it in GitHub Desktop.
Dancer error catching.
package kapowaz;
use Dancer ':syntax';
use Dancer::Serializer::Mutable;
our $VERSION = '0.1';
get '/' => sub {
template 'index';
};
# With error_template specified, show_errors off, and don't try to serialize
# shows me error.tt
prefix '/error_template';
get '/die' => sub {
set serializer => undef;
set show_errors => 0;
set error_template => "error.tt";
die "Fission Mailed";
};
# With show_errors turned on, and don't try to serialize
# shows me dancer stack trace
prefix '/show_errors';
get '/die' => sub {
set serializer => undef;
set show_errors => 1;
die "Fission Mailed";
};
# Show errors off, and default template used.
# Shows public/500.html
prefix undef;
get '/die' => sub {
set serializer => undef;
set show_errors => 0;
die "Fission Mailed";
};
# Returning JSON
# Returns JSON representation of the error - and ignores error.tt
prefix '/json';
get '/die' => sub {
set serializer => 'JSON';
set error_template => "error.tt";
set show_errors => 1;
die "Fission Mailed";
};
# Returning Mutable
# Returns mutable representation of the error - and ignores error.tt
prefix '/mutable';
get '/die' => sub {
set serializer => 'mutable';
set error_template => "error.tt";
set show_errors => 1;
die "Fission Mailed";
};
true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment