Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Unhandled promise rejections are deprecated #321

Open
XNinety9 opened this issue Oct 15, 2020 · 1 comment
Open

Unhandled promise rejections are deprecated #321

XNinety9 opened this issue Oct 15, 2020 · 1 comment

Comments

@XNinety9
Copy link

XNinety9 commented Oct 15, 2020

Hi there.

I've been using dialogflow-fulfillment-nodejs library for a few days now, so far, so good.

But when trying to request data from an external API within the fulfillment handler, I've been facing a tenacious error:

(node:67018) UnhandledPromiseRejectionWarning: Error: No responses defined for platform: DIALOGFLOW_CONSOLE
    at V2Agent.sendResponses_ (/Users/x99/Documents/Repositories/PROJECT/functions/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
    at WebhookClient.send_ (/Users/x99/Documents/Repositories/PROJECT/functions/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
    at /Users/x99/Documents/Repositories/PROJECT/functions/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
    at processPromiseRejections (internal/process/promises.js:247:11)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

Here's the code:

const { response } = require('express');
var https = require ('https');

function httpRequest(params, postData) {
	return new Promise(function(resolve, reject) {
		var req = https.request(params, function(res) {
			// reject on bad status
			if (res.statusCode < 200 || res.statusCode >= 300) {
				return reject(new Error('statusCode=' + res.statusCode));
			}
			// cumulate data
			var body = [];
			res.on('data', function(chunk) {
				body.push(chunk);
			});
			// resolve on end
			res.on('end', function() {
				try {
					body = JSON.parse(Buffer.concat(body).toString());
				} catch(e) {
					reject(e);
				}
				resolve(body);
			});
		});

		// reject on request error
		req.on('error', function(err) {
			// This is not a "Second reject", just a different sort of failure
			reject(err);
		});

		if (postData) {
			req.write(postData);
		}

		// IMPORTANT
		req.end();
	})
	.catch(function (error) {
		console.error("Promise rejected");
	});
}

exports.howManyTasks = function(agent) {
	console.log("[INFO] howManyTasks");
	
	const host = "myapihost.com"
	const path = "/api/users/myusertoken/task_lists";
	const bearerToken = "mybearertoken";
	
	var params = {        
        hostname: host,
        port: 443,
        path: path,
        method: 'GET',
        headers:{
            Authorization: ' Bearer ' + bearerToken            
       }
	};

	httpRequest(params).then(function(body) {
		console.log(body);
	})
	.catch(function () {
		console.error("Promise Rejected");
	});

	console.log("[INFO] I'm out!");
}

From what I see in the logs, the error comes from the library itself? Knowing that beyond the error, my code successfully retrieves the needed data from the API.

@DIALQGUE
Copy link

I have this error too, my code worked before when I deploy it. But after few hours (or other trigger, I don't know for sure) Dialogflow fulfillment's requests have changed and now it come with "originalDetectIntentRequest" field. And I stuck here for 3 days.

Are you found any solution for this? Or alternative library to use with dialogflow fulfillment? Since this library is deprecated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants