Dancer2 icon indicating copy to clipboard operation
Dancer2 copied to clipboard

deserializer error(HTTP Request).

Open jahagirdar opened this issue 7 years ago • 1 comments

I am getting the following error message for Failed to deserialize content: Class::XSAccessor: invalid instance method invocant: no hash ref supplied at /usr/local/share/perl/5.22.1/Dancer2/Core/Role/Serializer.pm line 71. in /usr/local/share/perl/5.22.1/Dancer2/Core/Request.pm l. 206

I tried inserting a print statement in Request.pm to see the content of the body parameter passed in line 207 as follows

use Data::Dumper;
print Dumper $body;
print Dumper $serializer;
    my $data = $serializer->deserialize($body);
    return if !defined $data;

These two print statements resulted in the following log messages

$VAR1 = '{"item":{"name":"uart","type":"test"}}';
$VAR1 = bless( {
                 'content_type' => 'text/html',
                 'log_cb' => sub { "DUMMY" },
                 'hooks' => {
                              'engine.serializer.before' => [],
                              'engine.serializer.after' => []
                            },
                 'config' => {}
               }, 'Dancer2::Serializer::Mutable' );

The complete HTTP response was as follows Note the content type above is 'text/html' instead of 'application/json' which was passed to Dancer2.

 bless( {
#                  '_content' => 'Internal Server Error
#
# Bad Content-Length: maybe client disconnect? (38 bytes remaining) at /usr/local/share/perl/5.22.1/Plack/Request.pm line 260.
# ',
#                  '_msg' => 'Internal Server Error',
#                  '_rc' => 500,
#                  '_headers' => bless( {
#                                         'content-type' => 'text/plain'
#                                       }, 'HTTP::Headers' ),
#                  '_request' => bless( {
#                                         '_content' => '{"item":{"name":"uart","type":"test"}}',
#                                         '_method' => 'POST',
#                                         '_uri' => bless( do{\(my $o = 'http://localhost/api/prjEdit/Project.json')}, 'URI::http' ),
#                                         '_headers' => bless( {
#                                                                'content-type' => 'application/json',
#                                                                'content-length' => 38
#                                                              }, 'HTTP::Headers' )
#                                       }, 'HTTP::Request' )
#                }, 'HTTP::Response' );

jahagirdar avatar Aug 12 '17 06:08 jahagirdar

Looping in @yanick, in case this is related to a pull request created from D2:P:REST https://github.com/PerlDancer/Dancer2-Plugin-REST/issues/15

jahagirdar avatar Aug 13 '17 13:08 jahagirdar