node-http-mitm-proxy icon indicating copy to clipboard operation
node-http-mitm-proxy copied to clipboard

No error when trying to listen on an in-use port

Open ks07 opened this issue 8 years ago • 1 comments

Calling proxy.listen({port:PORT_IN_USE}) where PORT_IN_USE is already being used by another process does not cause any immediate error. The library should throw an error if this is the case.

ks07 avatar Sep 29 '17 15:09 ks07

Nowadays, an error bubbles up when the port is already in use.

However, it is not caught by the callback given to proxy.listen, but rather in proxy.onError. This is somewhat unexpected...

const proxy = new Proxy();

proxy.onError(function (ctx: IContext, err: any) {
  // code here is triggered
});

proxy.listen({ port: PORT_IN_USE }, function (err) {
  if (err) {
    // code here isn't
  }
})

Pamplemousse avatar Mar 07 '23 10:03 Pamplemousse