Skip to content

Commit

Permalink
2.4.2 optimize error handling for webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Apr 30, 2020
1 parent 627d3b7 commit 1c07280
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ If no data source was specified or the noHistory parameter is passed, then only
</pre>

## Changelog
### 2.4.2 (2020-04-30)
### 2.4.3 (2020-04-30)
* (Apollon77) Optimize web server error handling

### 2.4.1 (2020-04-23)
Expand Down
4 changes: 2 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"common": {
"name": "simple-api",
"version": "2.4.2",
"version": "2.4.3",
"news": {
"2.4.2": {
"2.4.3": {
"en": "Caught the web server errors",
"de": "Fehler beim Webserver",
"ru": "Поймали ошибки веб-сервера",
Expand Down
8 changes: 5 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ function initWebServer(settings) {

if (server.server) {
let serverListening = false;
let serverPort = settings.port;
server.server.on('error', e => {
if (e.toString().includes('EACCES') && port <= 1024) {
adapter.log.error(`node.js process has no rights to start server on the port ${port}.\n` +
if (e.toString().includes('EACCES') && serverPort <= 1024) {
adapter.log.error(`node.js process has no rights to start server on the port ${serverPort}.\n` +
`Do you know that on linux you need special permissions for ports under 1024?\n` +
`You can call in shell following scrip to allow it for node.js: "iobroker fix"`
);
} else {
adapter.log.error(`Cannot start server on ${settings.bind || '0.0.0.0'}:${port}: ${e}`);
adapter.log.error(`Cannot start server on ${settings.bind || '0.0.0.0'}:${serverPort}: ${e}`);
}
if (!serverListening) {
adapter.terminate ? adapter.terminate(1) : process.exit(1);
Expand All @@ -134,6 +135,7 @@ function initWebServer(settings) {
}
return;
}
serverPort = port;

if (server.server) {
// create web server
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.simple-api",
"version": "2.4.2",
"version": "2.4.3",
"description": "RESTful interface for ioBroker.",
"author": {
"name": "bluefox",
Expand Down

0 comments on commit 1c07280

Please sign in to comment.