My RESTfull server with Perl Dancer runs perfectly with one exception: send_error("Simple Error string",400)
for example removes the error message.
The error code will be sent, but without the actual message "Simple Error string".
I tried return send_entity({ error => "Missing parameter "}, 400)
with no avail too.
Here is the code:
#!/usr/bin/perl
##########################################################################################################################################
# V1.0 REST-Server
##########################################################################################################################################
use Dancer;
use Dancer::Plugin::Auth::Basic;
use Dancer::Plugin::Database;
use Dancer::Plugin::REST;
set serializer => 'XML';
post '/hello/:name' => sub
{
# Low level test route
auth_basic realm => 'Authorized personnel only', users => { 'alice' => 'AlicesPassword', 'bob' => 'BobsPassword' };
send_error("Simple Error string",400);
};
dance;
The tests take place with curl:
#curl -X POST -k -u alice:AlicesPassword http://localhost:5000/hello/abc
An internal error occured
and with RESTer under Firefox (via https proxy).
RESTer reports the same.
Several googling brought no hints, how to produce the correct error code AND the provided message.
I hope anybody can give me a hint.
To simply change the Http status you can use the status
keyword and return your content as the response body.
get '/' => sub {
status 418;
return 'I cannot make coffee.';
};