0

when I try to query data from algolia using algolia search helper package in nodejs. randomly getting response in "error" event as below.when once got this error then always getting this error for the query till restart nodejs.

Error :-

{
 "name": "AlgoliaSearchUnparsableJSONError",
 "message": "Could not parse the incoming response as JSON, see err.more for details",
"more": "<html>\r\n<head><title>400 Request Header Or Cookie Too Large</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>Request Header Or Cookie Too Large</center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"`enter code here`

my code :-

var algoliasearch = require('algoliasearch');
var algoliasearchHelper = require('algoliasearch-helper');
var client = algoliasearch(ALGOLIA_CLIENT_ID,ALGOLIA_TOKEN);
var helper = algoliasearchHelper(client, ALGOLIA_INDEX, {
                   disjunctiveFacets: ['username'],
                   attributesToRetrieve: 'firstname,lastname'
             });
helper.on('result', function (data) {
});      
helper.on('error', function (data) {
});  
helper.clearRefinements();
helper.addDisjunctiveFacetRefinement('username', USERNAME);
helper.search();

}
Visakh C S
  • 3
  • 1
  • 2
  • First: You must separate de code and the error. Second: You can se the error is in the text, should ask better how to fix this exact error and no just put title: "Algolia AlgoliaSearchUnparsableJSONError". – josedlujan Jan 28 '17 at 18:41

2 Answers2

0

This is actually one error that is causing another. The unparseable JSON is because the Algolia server is returning HTML not JS when it replies with the 400 error. Maybe related to this Github issue.

The real question is what is eventually causing this 400 error in the first place. It looks like it's related to request header length (probably not cookie length since you're calling from Node). I would recommend logging request headers or analyzing the outgoing HTTP call through a proxy to see if the request is changing over time in an unexpected way.

Josh Dzielak
  • 1,803
  • 17
  • 19
0

The type of attributesToRetrieve is array of strings as it mentioned here

var helper = algoliasearchHelper(client, ALGOLIA_INDEX, {
  disjunctiveFacets: ['username'],
  attributesToRetrieve: ['firstname', 'lastname']
});
Parvez Rahaman
  • 4,269
  • 3
  • 22
  • 39