Invalid content-type sended by dancer when error 500 happens
Hi! I'm using Dancer 1.3093 (latest in ActiveState PPM) under Windows. I have created application using "dancer -a test" command, and modified test/lib/test.pm so now it looks like this: --beginning of code-- # This is application generated by "dancer -a test", only test/lib/test.pm was modified package test; use Dancer ':syntax'; use Exception::Class ( foobar => { description => 'Arguments passed to function are invalid.' }, ); our $VERSION = '0.1'; get '/' => sub { <<EOF; <!doctype html> <html> <head><title>test</title></head> <body> <form action="/" method="post"> <input type="text" name="login"><br> <input type="password" name="password"><br> <input type="submit" name="submit"> </form> </body> EOF }; post '/' => sub { die 'error!'; }; true; ---end of code--- When I run app.pl with argument "--environment=production", connect to the site with browser, and click "submit", Dancer returns error 500 (as expected), but instead of "text/html" Content-Type, it has "application/x-www-form-urlencoded" MIME type. What am I doing wrong? Thanks, Tomasz
Oops, forget about "Exception::Class" part, code should look like this: --begin-- # This is application generated by "dancer -a test", only test/lib/test.pm was modified package test; use Dancer ':syntax'; our $VERSION = '0.1'; get '/' => sub { <<EOF; <!doctype html> <html> <head><title>test</title></head> <body> <form action="/" method="post"> <input type="text" name="login"><br> <input type="password" name="password"><br> <input type="submit" name="submit"> </form> </body> EOF }; post '/' => sub { die 'error!'; }; true; --end--
Hi, Sorry it's a bit off topic, but if you want to use exceptions, Dancer already provides its own exception class(es), you should probably read the doc: https://metacpan.org/module/Dancer::Exception Now, about your issue, did you try to set a 500 custom error page ? On 15 March 2012 18:11, Tomasz Konojacki <xenu@poczta.onet.pl> wrote:
Oops, forget about "Exception::Class" part, code should look like this:
--begin--
# This is application generated by "dancer -a test", only test/lib/test.pmwas modified package test; use Dancer ':syntax';
our $VERSION = '0.1';
get '/' => sub { <<EOF; <!doctype html> <html> <head><title>test</title></**head> <body> <form action="/" method="post"> <input type="text" name="login"><br> <input type="password" name="password"><br> <input type="submit" name="submit"> </form> </body> EOF
};
post '/' => sub { die 'error!'; };
true; --end--
______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
Also, could someone confirm this problem? I want to know whether it is happening to just me. Thanks, Tomasz
On Sat, Mar 17, 2012 at 7:04 PM, Tomasz Konojacki <xenu@poczta.onet.pl>wrote:
Also, could someone confirm this problem? I want to know whether it is happening to just me.
Hi. I'm sorry to have this topic delayed for a week now. Basically by "die()"ing, you're forcing the perl interpreter to close. You're providing a bad result to the web server by shutting off the app, and you're returning the exit code of die() to the user. In effect if you were to save the result to a file, you'll get a 500 error page. The reason you're not getting this in an actual proper html output and instead get it in x-www-form-urlencode, I believe is because you're crashing the app. This is why "die()" should never be used in *any* web application (Dancer/Catalyst/CGI/etc.). You should instead use whatever the web application provides you with in order to halt the requests properly and return an error to the user. You should look at Dancer's exception system, or return an html with the problem. S.
participants (3)
-
damien krotkine -
sawyer x -
Tomasz Konojacki