Stwissel / node-red-contrib-salesforce

A set of Node-RED nodes to interact with Salesforce and Force.com
MIT License
10 stars 17 forks source link

DML node raising error: "Cannot read property 'toLowerCase' of null" #38

Closed dwindibank closed 1 year ago

dwindibank commented 5 years ago

The workflow I am using worked on the version 0.2.6, but on 0.7.2 it raises an error.

The error is caught by the NodeRed debug node. The DML statement I am executing looks like this (I am trying to update the account):

{
  "Id":"0000000000XXXXXXXX",
  "AccountId":"0000000000XXXXXXX",
   "attributes":{"type":"Contact"}
}

The update works fine, but the following error is raised:

{
"message":"TypeError: Cannot read property 'toLowerCase' of null",
"source":{"id":"7a76873c.7f3788","type":"dml","name":"Update contact","count":1},
"stack":"TypeError: Cannot read property 'toLowerCase' of null
    at Object.util.isJsonResponse (/home/user/.node-red/node_modules/nforce8/lib/util.js:6:42)
    at fetch.then.then.then (/home/user/.node-red/node_modules/nforce8/index.js:913:30)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)"
}

That line of code is doing callin toLowerCase on the content-type header ... the original nforce library a check in that function to make sure the content-type header isn't null.

Notes:

guillaume-loubier commented 5 years ago

@dwindibank @Stwissel did you found a workaround for that issue yet? I could fork and fix it with a check for null value, but I'm not really setup to debug any of that as I'm more on the Salesforce side and helping a collegue with the communication between node red and us.

dwindibank commented 5 years ago

@darkjacko, sorry for not responding sooner. I patched the util.js class with the fix from the source library (nforce). I plan to consolidate the changes to the util.js file from the nforce library into the nforce8 library and post it as a pull request to nforce8.

There are some other improvements in that file but the main fix is updating the "isJsonRespone" function to not require that the content-type header is in the response.

This is what the changed function looks like:

util.isJsonResponse = function(res) {

return res.headers &&
    res.headers['content-type'] &&
    res.headers['content-type'].split(';')[0].toLowerCase() === 'application/json';
};
dwindibank commented 5 years ago

Ah, I spoke too soon. It was an easy fix but to get past the isJsonRespone issue, but much of the code in node-red-contrib-salesforce expects the payload to be Json.

So, now I'm getting the following error from line 22 of the SOQL node:

TypeError: Cannot create property 'records' on string {"totalSize":11,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v41.0/sobjects/Contact/...

Stwissel commented 5 years ago

@dwindibank - you can throw what you have over the fence and I'll finish it up

ramoriusvt commented 5 years ago

I'm having this issue as well. In my situation, I'm updating an existing record (so I know the id) successfully and receiving the following 204 No Content response: HTTP/1.1 204 No Content Node Red is apparently not recognizing the 204 as a successful response and attempting to parse the response. That's generating the error "message":"TypeError: Cannot read property 'toLowerCase' of null". I confirmed (via Workbench) that Salesforce REST api is indeed returning the No Content response. It's just that Node Red isn't handling it properly. Hopefully this will help. Thank you, Rob

ramoriusvt commented 5 years ago

I was handling this by Catching the error. That isn't going to work if I have more than one update in a flow. We really need Node Red to recognize and accept a 204 response as successful without generating a subsequent error.

Swiftnesses commented 2 years ago

Has anyone found a nice way of suppressing this error?

J-Inn commented 1 year ago

Hi - Does anyone know when this might be fixed? or is addressed in node-red-contrib-c1-salesforce[5] ?

Stwissel commented 1 year ago

fixed in 0.8