From 9a8f60767b6eeeee9199ff73a5a2b2821c27b6cf Mon Sep 17 00:00:00 2001 From: James Sumners Date: Tue, 27 Aug 2019 19:01:47 -0400 Subject: [PATCH] Resolve issue #336 --- docs/examples.md | 2 +- docs/guide.md | 4 ++-- test/errors.test.js | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index 656bded..c12f93c 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -289,7 +289,7 @@ with ldapjs. var entry = req.toObject().attributes; if (entry.objectclass.indexOf('unixUser') === -1) - return next(new ldap.ConstraintViolation('entry must be a unixUser')); + return next(new ldap.ConstraintViolationError('entry must be a unixUser')); var opts = ['-m']; if (entry.description) { diff --git a/docs/guide.md b/docs/guide.md index 6fb056c..1c56a34 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -409,7 +409,7 @@ the following code in as another handler (you'll need a var entry = req.toObject().attributes; if (entry.objectclass.indexOf('unixUser') === -1) - return next(new ldap.ConstraintViolation('entry must be a unixUser')); + return next(new ldap.ConstraintViolationError('entry must be a unixUser')); var opts = ['-m']; if (entry.description) { @@ -496,7 +496,7 @@ As before, here's a breakdown of the code: var entry = req.toObject().attributes; if (entry.objectclass.indexOf('unixUser') === -1) - return next(new ldap.ConstraintViolation('entry must be a unixUser')); + return next(new ldap.ConstraintViolationError('entry must be a unixUser')); A few new things: diff --git a/test/errors.test.js b/test/errors.test.js index a2c592a..6b66a8a 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -1,7 +1,14 @@ 'use strict' const { test } = require('tap') -const { LDAPError, ConnectionError, AbandonedError, TimeoutError, LDAP_OTHER } = require('../lib') +const { + LDAPError, + ConnectionError, + AbandonedError, + TimeoutError, + ConstraintViolationError, + LDAP_OTHER +} = require('../lib') test('basic error', function (t) { const msg = 'mymsg' @@ -14,6 +21,17 @@ test('basic error', function (t) { t.end() }) +test('exports ConstraintViolationError', function (t) { + const msg = 'mymsg' + const err = new ConstraintViolationError(msg, null, null) + t.ok(err) + t.equal(err.name, 'ConstraintViolationError') + t.equal(err.code, 19) + t.equal(err.dn, '') + t.equal(err.message, msg) + t.end() +}) + test('"custom" errors', function (t) { const errors = [ { name: 'ConnectionError', Func: ConnectionError },