lbdremy/solr-node-client

UnhandledPromiseRejectionWarning Error

ranrao opened this issue ยท 16 comments

Hello All,

I'm using Node 14 and seem to be running into this error when adding simple test data to solr:

const solr = require('solr-client');
const client = solr.createClient();

client.add({ id: 12, title_t: 'Hello' }, function(err, obj) {
       if (err) {
            console.log(err);
        } else {
            console.log('Solr response:', obj);
        }
}

(node:39116) UnhandledPromiseRejectionWarning: Error: Request HTTP error 404:
at Client.doRequest (..../node_modules/solr-client/dist/lib/solr.js:141:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:39116) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:39116) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Appreciate any help. Thank you

I would strongly recommend giving latest RC version a try. It uses a much friendlier promise API that should be easier to consume. Main reason why it's not final yet is because we still need to update documentation, but it should be pretty stable and ready for production (and actually significantly more performant than the current stable version).

Thank you @kibertoad. I'm using "solr-client": "^0.10.0-rc8",, should we try another version?

Or should I change anything in the sample code?

Appreciate any leads to overcome the error. Thank you

@ranrao Ah, that explains it. You are trying using it with callback API which is no longer supported. Remove the callback parameter and just await this call.

Let me update the sample.

Code sample would really help. Thanks so much for the prompt response.

@ranrao Updated most important examples in examples directory as well as readme.

@ranrao Please let me know how it goes!

Thank you @kibertoad. Still seeing this error:

Error: Request HTTP error 404:
at Client.doRequest (.../node_modules/solr-client/dist/lib/solr.js:141:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async index (/..../index.js:36:21)

My line 36 is const obj = await client.add([item]);

try {
        const obj = await client.add([item]);
        console.log(obj);
    } catch (e) {
        console.log(e);
    }

Any idea why 404 error?

Can you confirm that solr is running and client url is configured correctly?

brew services start solr
==> Successfully started solr (label: homebrew.mxcl.solr)

In terms of client url, this is the initial code:

const solr = require('solr-client');
const client = solr.createClient();

Trying this simple command also fails.

try {
        const obj = await client.add({ id: 12, title_t: 'Hello' });
        console.log(obj);
    } catch (e) {
        console.log(e);
    }

Am I missing anything in setup? Kindly update.

@ranrao Default host is 127.0.0.1, default path is /solr', default port is 8983. Check if you can access SolrUI (admin panel) using such values; if not, pass correct version of these parameters to createClient

Ah, another reason might be that you are using non-existing Solr core. Default is an empty one, you probably want to create and use a specific one.

Sure, thanks @kibertoad. Will create a Solr core and try again.

Any documentation that helps in creating a simple Solr core? We are switching from Elastic Search to Solr, and hence the learning curve. Thanks so much.

@ranrao Do you use Docker? This is how we init Solr Docker image:

services:
  solr:
    container_name: solr_dev
    image: solr:8.9.0
    ports:
      - "8983:8983"
    networks:
      - proxynet
    volumes:
      - data:/root/solr
      - /root/solr:/opt/solr-8.9.0/customSettings
    entrypoint:
      - bash
      - "-c"
      - "precreate-core testcore; precreate-core vehicles; precreate-core users /opt/solr-8.9.0/customSettings/users; precreate-core organizations; precreate-core classifiers; precreate-core departments; precreate-core roles; exec solr -f"
    hostname: solr_hostname

Alternatively see this: https://www.tutorialspoint.com/apache_solr/apache_solr_core.htm

Thank you @kibertoad. Tried creating a Solr core and it is all working very well now. Such timely help. Really appreciate it.

You are welcome! Please don't be a stranger and let us know if you'll need any help in the future.