Error handling on https.createserver()?

142 views
Skip to first unread message

O haya

unread,
Mar 15, 2017, 12:56:03 PM3/15/17
to nodejs

Hi,


Apologies in advance, but I posted about this on Stackoverflow, but I have tried many things and nothing seems to work for my problem, so I am posting here, hoping that someone can help.


I have been trying to implement handling errors in our Node.JS app when there is an error when we do https.createServer().  In particular, we want to handle an error when the password for the .pfx file is not correct.  


I found this thread:


Node.js http.createServer how to get error


but I cannot seem to make it work :(...


Here is my code:


var fs = require('fs');
var https = require('https');
// Setup HTTPS
var options = {
  pfx: fs.readFileSync('../security/server.pfx'),
  passphrase: XXXXX
};
console.log("++++++++ Listen SSL Mode ++++++++");
var secureServer = https.createServer(options, app);
secureServer.on('error', function (e) {
    // Handle your error here
    console.log(e);
    });
secureServer.listen(LISTENPORT);


When I try that, it's like the "secureServer.on()' is not being processed at all:


++++++++ Listen SSL Mode ++++++++
_tls_common.js:137
      c.context.loadPKCS12(pfx, passphrase);
                ^

Error: mac verify failure
    at Error (native)
    at Object.createSecureContext (_tls_common.js:137:17)
    at Server (_tls_wrap.js:768:25)
    at new Server (https.js:26:14)
    at Object.exports.createServer (https.js:47:10)



We know that (we have tried this) using process.on() to catch an uncaughtexception seems to work, but we would like to catch (and handle) this particular situation (bad/incorrect password) more specifically.


Can someone tell me what I might be doing wrong?


I have also tried using the ".on('error',...)" on the ".listen()" but that doesn't do anything.


Thanks, Jim

Reply all
Reply to author
Forward
0 new messages