Action fails with HTTP 500 on some AJAX POST requests

AJAX POST requests containing complex JSON data structure sent to a controller fails with HTTP 500. The controller has an empty action configured to the POST route with

bundle exec hanami generate action web home#test --method=post

This AJAX fails:
$.ajax({
url: engineURL,
type: ‘POST’,
dataType: ‘json’,
data: {“info”: [“test”, [{x:0, y:1}]]},
async: false
});

Another real life example that fails is:
dataArr = Array.from(dataMap)

data: {“info”: dataArr},

But this one works:
$.ajax({
url: engineURL,
type: ‘POST’,
dataType: ‘json’,
data: {“test”: [{x:0, y:1}]},
async: false
});

It’s not a JS or JSON conversion issue as any of the above data structures may be stringified with JSON.stringify() without errors

Could you post the stack trace of the hanami server when those requests fail?

1 Like

I’m new to Hanami, how can I get a stack trace taking into account it’s AJAX i.e. nothing is returned to the browser?

You may want to have a look at the console where you started the Hanami server (via bundle exec hanami server). This is the place where usually you can see the stack trace of exceptions raised by the app.