[Dancer-users] Confused on error reporting
Stephen Fenwick-Paul
stephen at activeg.org
Thu Jul 7 09:56:53 CEST 2011
Hi all,
I've done some reading on how RESTful apps should respond to errors, but I'm
getting confused on how Dancer handles this for me.
My simple app:
package Test;
use Dancer ':syntax';
use Dancer::Plugin::Ajax;
# Case 1: Just a normal web page with layout
get '/error.html' => sub {
eval {
die "HTML die";
} or do {
send_error("HTML: You made a mistake", 400);
};
};
# Case 2: A json call
get '/error.json' => sub {
set serializer => 'JSON';
eval {
die "JSON die";
} or do {
send_error("JSON: You made a mistake", 400);
};
};
# Case 3: HTML being return from an ajax call, thus no layout
ajax '/error.html' => sub {
eval {
die "AJAX die";
} or do {
send_error("AJAX: You made a mistake", 400);
};
};
With the environment set to development, each of these responds as I expect.
Case 1 gives me a full backtrace, case 2 gives me a a json with just the
error message, and case 3 again give me a full backtrace,
Now moving to the production environment. I get
$ curl http://127.0.0.1:3000/error.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Error 400</title>
<link rel="stylesheet" href="/css/style.css" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Error 400</h1>
<div id="content">
<h2>Unable to process your query</h2>The page you requested is not available
</div>
<div id="footer">
Powered by <a href="http://perldancer.org/">Dancer</a> 1.3060
</div>
</body>
Which is OK, but where is the meaningful message to the user gone?
$ curl http://127.0.0.1:3000/error.json
"An internal error occured"
Again, not very useful.
$ curl -H 'X-Requested-With: XMLHttpRequest'
http://127.0.0.1:3000/error.html
"An internal error occured"
I need to send something more than this back to the client.
What am I doing wrong?
If I declare my own error template:
set error_template => 'error';
Then, again, in development every thing is as expected, but in production I
get "An internal error occured" in all 3 cases.
My production,yml is the standard one.
Thanks for any insights.
Stephen
P.S. occured should be occurred
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110707/eaeadca0/attachment.htm>
More information about the Dancer-users
mailing list