Coder Social home page Coder Social logo

Handle request timeout error about yamaha-nodejs HOT 5 OPEN

pseitz avatar pseitz commented on June 7, 2024
Handle request timeout error

from yamaha-nodejs.

Comments (5)

PSeitz avatar PSeitz commented on June 7, 2024

Probably same as #7

Did you try catching and handling the errors from the promise?

from yamaha-nodejs.

bogdanim36 avatar bogdanim36 commented on June 7, 2024

I don't know how to do this :(.
I find the line with prom.catch method:

Yamaha.prototype.SendXMLToReceiver = function(xml) {
    var self = this;
    return this.getOrDiscoverIP().then(ip => {
        var isPutCommand = xml.indexOf("cmd=\"PUT\"" >= 0);
        var delay = isPutCommand ? this.responseDelay * 1000 : 0;
        var req = {
            method: 'POST',
            uri: 'http://' + ip + '/YamahaRemoteControl/ctrl',
						body: xml
			  };
				if (this.requestTimeout) req.timeout = this.requestTimeout;

				var prom = request.postAsync(req).delay(delay).then(response => response.body)
				if (self.catchRequestErrors === true) prom.catch(console.log.bind(console));

        return prom

    })
};

prom.catch method is fired on timeout error, but i don't know to do in callback , to stop exit app.listen.

It's not the same as #7. I receive ETIMEOUT error from nodejs server.

from yamaha-nodejs.

PSeitz avatar PSeitz commented on June 7, 2024

I meant same as in #7 as the errors are not handled by the user.

The lib returns bluebird promises: http://bluebirdjs.com/docs/api-reference.html
Catch all errors:

yamaha.setMainInputTo("HDMI2").then(function() {
    return yamaha.getCurrentInput();
}).catch(function(e) {

});

With the catchRequestErrors the lib swallows errors and prints them.

from yamaha-nodejs.

bogdanim36 avatar bogdanim36 commented on June 7, 2024

I did now like this:

var yamahaApi = require("yamaha.api")
var yamahaCtrl = new yamahaApi("192.168.1.2");
and the call 
yamaha.getBasicInfo(zone).then(function (info) {
	res.send(info);
}).catch(function (error) {
	res.send(error);
});

and server still exit with error ETIMEDOUT.

from yamaha-nodejs.

bogdanim36 avatar bogdanim36 commented on June 7, 2024

I think I solved. with the solution above.
I added a lot of commands on yamaha.simple.commands.api.js.:

Yamaha.prototype.getRepeatInfo = function (input) {
var command = '<YAMAHA_AV cmd="GET"><' + input + '><Play_Control><Play_Mode>GetParam</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command).then(xml2js.parseStringAsync);
};

Yamaha.prototype.repeatOff = function (input) {
var command = '<YAMAHA_AV cmd="PUT"><' + input + '><Play_Control><Play_Mode>Off</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.repeatAll = function (input) {
var command = '<YAMAHA_AV cmd="PUT"><' + input + '><Play_Control><Play_Mode>All</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.repeatOne = function (input) {
var command = '<YAMAHA_AV cmd="PUT"><' + input + '><Play_Control><Play_Mode>One</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.getShuffleInfo= function (input) {
var command = '<YAMAHA_AV cmd="GET"><' + input + '><Play_Control><Play_Mode>GetParam</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command).then(xml2js.parseStringAsync);
};

Yamaha.prototype.shuffleOn = function (input) {
var command = '<YAMAHA_AV cmd="PUT"><' + input + '><Play_Control><Play_Mode>On</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.shuffleOff = function (input) {
var command = '<YAMAHA_AV cmd="PUT"><' + input + '><Play_Control><Play_Mode>Off</Play_Mode></Play_Control></' + input + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.menuCursorMove = function (listname, move) {
if (["Return", "Up", "Down"].indexOf(move) === -1) throw "Cursor move can be only Retur, Up or Down";
var command = '<YAMAHA_AV cmd="PUT"><' + listname + '><List_Control>' + move + '</List_Control></' + listname + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.menuPageMove = function (listname, move) {
if (["Up", "Down"].indexOf(move) === -1) throw "Cursor move can be only Retur, Up or Down";
var command = '<YAMAHA_AV cmd="PUT"><' + listname + '><List_Control>' + move + '</List_Control></' + listname + '></YAMAHA_AV>';
return this.SendXMLToReceiver(command);
};

Yamaha.prototype.getSERVERList = function () {
return this.getList("SERVER");
};

from yamaha-nodejs.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.