Click here to Skip to main content
14,449,862 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have below code snippet which is giving me an error. I am getting a response back from getFilteredList which is of lenght 1 and it has a proper json data. But not sure why its giving error.

TypeError: Cannot read property 'then' of null


getFilteredList(group, feature).then(r=>{ //here I am getting error. 
    if(r.data.response_code == "1")
    {
      const columnName = "ColumnName";
      const Codes = r.data.response_message.map(x => x[columnName]);
      Codes.forEach(code => {
        let store = getStoreValue(code);
        getDetailsById(id, datastore)
        .then(r=>{
          res.status(200).send(r.data);
        }).catch(e=>{
          parseError(e, res);
        });
      })
    }
  }).catch(e=>{
      parseError(e, res);
    });
}


What I have tried:

getFilteredList() a another node js service which is returning a data when I tested it using Saop UI. I can see it in logs as well of application. I am not getting why it is saying null though having a data
Below is sample data it returns.
{"CODE":"AGR","GRP":"LEND","FEAT_CODE":"SRC_AGREE","GROUP_NAME":"Prop","FEA_NAME":"Property","DISPLAY_NAME":"Property","ROLE_CODE":"LE"}
Posted
Updated 5 days ago
v3

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

getFilteredList(group, feature).then(r=>{

The message simply means that the call to getFilteredList does not return anything.
   
v2
Comments
Telstra 5 days ago
   
But this same call is working in my one more node js service where this call is returning a data.
getDetailsById(adgroup, featureSet).then(r=>{ -- this line is working fine here.
if(r.data.response_code == "1") -- this condition is working fine.
{
}
Richard MacCutchan 5 days ago
   
Sorry I copied the wrong line of your question; see updated code above. You need to use your debugging tools to find out why it does not return anything.
Telstra 5 days ago
   
getFilteredList() is another node js service which itself returns json data and I can see that data in logs. Below is the data it returns.

{"CODE":"AGR","GRP":"LEND","FEAT_CODE":"SRC_AGREE","GROUP_NAME":"Prop","FEA_NAME":"Property","DISPLAY_NAME":"Property","ROLE_CODE":"LE"}
F-ES Sitecore 5 days ago
   
You might think that is what it is returning, but it isn't, it is returning null, ergo the error.
Telstra 5 days ago
   
I got that response from logs and I can see that in json string variable as well from getFilteredList() service.
Richard MacCutchan 5 days ago
   
That is irrelevant. The problem is clearly that the call to getFilteredList does not return anything. And, as F-ES Sitecore already told you, that is why you get the error. Whatever you see in the logs does not prove what your code is doing.
Telstra 5 days ago
   
Also I am using getFilteredList() service in another file as well where it is working fine with same lines of code block. Not sure why its not working here.
Richard MacCutchan 5 days ago
   
As I already suggested, use your debugging tools to find out. There is no way anyone here can do it for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100