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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<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">
</div>
</body>
Which is OK, but where is the meaningful message to the user gone?
"An internal error occured"
Again, not very useful.
"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