Skip to content

Commit 952e01d

Browse files
committed
Ignore favicon requests. Output error to http stream if no system found
1 parent 4c9b66f commit 952e01d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/sonos-http-api.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ const logger = require('sonos-discovery/lib/helpers/logger');
66

77
function HttpAPI(discovery, settings) {
88

9-
var port = settings.port;
10-
var webroot = settings.webroot;
11-
var actionsDir = __dirname + '/actions';
12-
var actions = {};
9+
const port = settings.port;
10+
const webroot = settings.webroot;
11+
const actions = {};
1312

1413
this.getWebRoot = function () {
1514
return webroot;
@@ -48,18 +47,23 @@ function HttpAPI(discovery, settings) {
4847
});
4948

5049
this.requestHandler = function (req, res) {
51-
if (discovery.zones.length === 0) {
52-
res.writeHead(500, 'No system has been found yet.');
50+
if (req.url === '/favicon.ico') {
5351
res.end();
54-
logger.error('No system has yet been discovered. Please see https://github.com/jishi/node-sonos-http-api/issues/77 if it doesn\'t resolve itself in a few seconds.');
5552
return;
5653
}
5754

58-
var params = req.url.substring(1).split('/');
55+
if (discovery.zones.length === 0) {
56+
const msg = 'No system has yet been discovered. Please see https://github.com/jishi/node-sonos-http-api/issues/77 if it doesn\'t resolve itself in a few seconds.';
57+
logger.error(msg);
58+
sendResponse(500, { status: 'error', error: msg });
59+
return;
60+
}
61+
62+
const params = req.url.substring(1).split('/');
5963

60-
var player = discovery.getPlayer(decodeURIComponent(params[0]));
64+
let player = discovery.getPlayer(decodeURIComponent(params[0]));
6165

62-
var opt = {};
66+
const opt = {};
6367

6468
if (player) {
6569
opt.action = (params[1] || '').toLowerCase();

0 commit comments

Comments
 (0)