mercredi 2 septembre 2015

Socket Hang Up Error in Amazon Echo Development

I've been having some problems with an https request using the lambda function. I'm getting the following error:

{
    "errorMessage": "socket hang up",
    "errorType": "Error",
    "stackTrace": [
    "SecurePair.error (tls.js:1011:23)",
    "EncryptedStream.CryptoStream._done (tls.js:703:22)",
    "CleartextStream.read [as _read] (tls.js:499:24)",
    "CleartextStream.Readable.read (_stream_readable.js:341:10)",
    "EncryptedStream.onCryptoStreamFinish (tls.js:304:47)",
    "EncryptedStream.g (events.js:180:16)",
    "EncryptedStream.emit (events.js:117:20)",
    "finishMaybe (_stream_writable.js:360:12)",
    "endWritable (_stream_writable.js:367:3)",
    "EncryptedStream.Writable.end (_stream_writable.js:345:5)"
]
}

from the following code. This code is written in Amazon's AWS Lambda service, in Nodejs.

var https = require('https');
var options = {
    host: 'host.dynamic.com', // global IP goes here. I've tried a DDNS host and the address of my server
    port: 8080,
    method: 'POST',
    headers: {
        'Content-Type': 'text'
    }
};
var data = 'OFF';

/**
* Pass the data to send as `event.data`, and the request options as
* `event.options`. For more information see the HTTPS module documentation
* at http://ift.tt/1DoGL84.
*
* Will succeed with the response body.
*/
exports.handler = function(event, context) {
    var req = https.request(options, function(res) {
    var body = '';
    console.log('Status:', res.statusCode);
    console.log('Headers:', JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function(chunk) {
        body += chunk;
    });
    res.on('end', function() {
    console.log('Successfully processed HTTPS response');
    // If we know it's JSON, parse it
    if (res.headers['content-type'] === 'application/json') {
        body = JSON.parse(body);
    }
    context.succeed(body);
});
});
console.log("Before the error");
req.on('error', context.fail);
req.write(data);
console.log("Before req.end()");
req.end();
};

Any help would be appreciated




Aucun commentaire:

Enregistrer un commentaire