I got this error because i was using a Search-Only API key to call saveObjects() .
in this quickstart code
The error message was unrelated to the actual cause. I added in multiple try / catch blocks and handled the error in the .catch() function so there should have been no reason to have this error, and it was masking the actual cause which i found out by trial and error. This seems like it might be a defect, it is throwing the wrong error
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v20.3.1
code
const client = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_ADMIN_API_KEY);
const index = client.initIndex(ALGOLIA_INDEX_NAME);
const newObject = { objectID: 1, name: "Foo" };
try {
index.saveObjects([newObject]).wait()
.then((response) => {
console.log(response);
index.search("Fo").then((objects) => {
console.log(objects);
}).catch( (err1) => {
console.error(err1);
});
}) ;
} catch (err3) {
console.error(err3);
}