The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Dancer::RPCPlugin::DefaultRoute - Catch bad-requests and send error-response

SYNOPSIS

    use Dancer::RPCPlugin::DefaultRoute;
    setup_default_route();

DESCRIPTION

Implements default endpoint to generate -32601 'method not found' or 'path not found' error_response for non existing endpoints

setup_default_route

Installs a Dancer route-handler for any qr{.+} which tries to return an appropriate error response to the requestor.

Responses

All responeses will have status: 200 OK

The content-type (and body) of the request determine the error-response:

text/xml

If the body is valid XMLRPC, the response is an XMLRPC-fault:

    faultCode   => -32601
    faultString => "Method '%s' not found"

If the body is not valid XMLRPC, the response is an XMLRPC-fault:

    faultCode   => -32600
    faultString => "Invaild xml-rpc. Not configming to spec: $@"
application/json

If the body is valid JSONRPC (ie. is has a 'jsonrpc': '2.0' field/value), the response is a JSONRPC-error:

    code => -32601
    message => "Method '%s' not found"

If the body is not valid JSONRPC, the response is a generic json struct:

    'error': {
        'code':  -32601,
        'message': "Method '$request->path' not found"
    }
other/content-type

Any other content-type is outside the scope of the service. We can respond in any way we like. For the moment it will be:

    status(404)
    content_type('text/plain')
    body => "Error! '$request->path' was not found for '$request->content_type'"

COPYRIGHT

(c) MMXX - Abe Timmerman <abetim@cpan.org>