From ed54323ef8a7b1b330ae35ad51fa9a3438bf35d2 Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Tue, 17 Dec 2019 15:09:16 +0100 Subject: [PATCH] Proxy errors include EINVAL errno. --- src/proxy.cc | 4 ++-- test/unit/proxy-run-test.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/proxy.cc b/src/proxy.cc index 08808e83..f2d8da12 100644 --- a/src/proxy.cc +++ b/src/proxy.cc @@ -52,13 +52,13 @@ Napi::Value Proxy::Run(const Napi::CallbackInfo& info) { if (Env().IsExceptionPending()) return Env().Undefined(); if (front->endpoints == 0) { - Napi::Error::New(Env(), "Front-end socket must be bound or connected") + ErrnoException(Env(), EINVAL, "Front-end socket must be bound or connected") .ThrowAsJavaScriptException(); return Env().Undefined(); } if (back->endpoints == 0) { - Napi::Error::New(Env(), "Back-end socket must be bound or connected") + ErrnoException(Env(), EINVAL, "Back-end socket must be bound or connected") .ThrowAsJavaScriptException(); return Env().Undefined(); } diff --git a/test/unit/proxy-run-test.ts b/test/unit/proxy-run-test.ts index 89040abb..743d3a83 100644 --- a/test/unit/proxy-run-test.ts +++ b/test/unit/proxy-run-test.ts @@ -56,6 +56,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } catch (err) { assert.instanceOf(err, Error) assert.equal(err.message, "Back-end socket must be bound or connected") + assert.equal(err.code, "EINVAL") + assert.typeOf(err.errno, "number") } }) @@ -70,6 +72,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } catch (err) { assert.instanceOf(err, Error) assert.equal(err.message, "Back-end socket must be bound or connected") + assert.equal(err.code, "EINVAL") + assert.typeOf(err.errno, "number") } }) })