On Tue, Sep 25, 2012, at 09:01 AM, Alfie John wrote:
sub Handle { my ( $handler ) = @_;
set serializer => 'JSON';
my $result;
return sub { my $user = ...
if ( not $user ) { log_stuff(); client_error( "User not found or incorrect password", 401 ); }
var user => $user;
other_stuff();
$result = $handler->( @_ ); };
if ( $@ ) { status( 500 ); error( $@ );
return { Status => 'Error', ErrorMessage => 'Internal server error', }; }
return $result; }
Oops. Wrongly copied. What I've got is: if ( $@ ) { if ( ref( $@ ) and $@ =~ /Dancer/ ) { $@->rethrow(); } status( 500 ); error( $@ ); return { Status => 'Error', ErrorMessage => 'Internal server error', }; } The reasoning here is that if my convenience method client_error() gets called somewhere in the code, it will eventually call send_error(). This error handler then gets called which rethrows with the proper client error message given in client_erro() instead of the default 'Internal server error'. Alfie -- Alfie John alfiej@opera.com