I'm having a problem with the node-red-contrib-salesforce that depends on this in that when SF returns anything other than an OK response, I can't see the returned message.
It appears that the problem is in the res.text() and res.json() functionality. Both functions return Promises, and therefore no contents are getting assigned. The example from the node-fetch github (https://github.com/node-fetch/node-fetch/blob/main/example.js) shows:
// Plain text or HTML
const response = await fetch('https://github.com/');
const body = await response.text();
console.log(body);
// JSON
const response = await fetch('https://github.com/');
const json = await response.json();
console.log(json);
<It is immensely frustrating (to have to resort to Postman) to get an integration working with Salesforce.>
I fixed the issue with the following:
async function unsucessfullResponseCheck(res, self, opts) {
// Only interested when stuff went wrong
if (res.ok) {
return res;
}
const e = new Error();
e.statusCode = res.status;
const body = util.isJsonResponse(res) ? await res.json() : await res.text();
...
<namely, putting 'async' before the function definition, and 'await ' before the assignments to body.>
I also addressed the res.txt() error previously identified.
Please let me know if there're any questions or if there is anything else I can do.
Thank you
I'm having a problem with the node-red-contrib-salesforce that depends on this in that when SF returns anything other than an OK response, I can't see the returned message.
It appears that the problem is in the res.text() and res.json() functionality. Both functions return Promises, and therefore no contents are getting assigned. The example from the node-fetch github (https://github.com/node-fetch/node-fetch/blob/main/example.js) shows:
<It is immensely frustrating (to have to resort to Postman) to get an integration working with Salesforce.>
I fixed the issue with the following:
<namely, putting 'async' before the function definition, and 'await ' before the assignments to body.>
I also addressed the res.txt() error previously identified.
Please let me know if there're any questions or if there is anything else I can do.
Thank you