diff --git a/src/externalldap.js b/src/externalldap.js index 17309734b..9a579a76d 100644 --- a/src/externalldap.js +++ b/src/externalldap.js @@ -122,7 +122,7 @@ async function getClient(config, options) { client = ldap.createClient(ldapConfig); } catch (e) { if (e instanceof ldap.ProtocolError) throw new BoxError(BoxError.BAD_FIELD, 'url protocol is invalid'); - throw new BoxError(BoxError.INTERNAL_ERROR, e); + throw new BoxError(BoxError.INTERNAL_ERROR, `Client creation error: ${e.message}`); } return await new Promise((resolve, reject) => { @@ -136,7 +136,7 @@ async function getClient(config, options) { client.bind(config.bindDn, config.bindPassword, function (error) { if (error instanceof ldap.InvalidCredentialsError) return reject(new BoxError(BoxError.INVALID_CREDENTIALS, 'Incorrect bind password')); - if (error) return reject(new BoxError(BoxError.EXTERNAL_ERROR, error)); + if (error) return reject(new BoxError(BoxError.EXTERNAL_ERROR, `Bind error: ${error.message}`)); resolve(client); }); @@ -154,12 +154,12 @@ async function clientSearch(client, dn, searchOptions) { return await new Promise((resolve, reject) => { client.search(dn, searchOptions, function (error, result) { if (error instanceof ldap.NoSuchObjectError) return reject(new BoxError(BoxError.NOT_FOUND, `dn not found ${dn}`)); - if (error) return reject(new BoxError(BoxError.EXTERNAL_ERROR, error)); + if (error) return reject(new BoxError(BoxError.EXTERNAL_ERROR, `search error: ${error.message}`)); const ldapObjects = []; result.on('searchEntry', entry => ldapObjects.push(entry.object)); - result.on('error', error => reject(new BoxError(BoxError.EXTERNAL_ERROR, error))); + result.on('error', error => reject(new BoxError(BoxError.EXTERNAL_ERROR, `search error: ${error.message}`))); result.on('end', function (result) { if (result.status !== 0) return reject(new BoxError(BoxError.EXTERNAL_ERROR, 'Server returned status ' + result.status)); @@ -345,7 +345,7 @@ async function verifyPassword(username, password, options) { const [error] = await safe(util.promisify(client.bind.bind(client))(userAuthDn, password)); client.unbind(); if (error instanceof ldap.InvalidCredentialsError) throw new BoxError(BoxError.INVALID_CREDENTIALS, error.lde_message); - if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, error); + if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `Bind error: ${error.message}`); const user = translateUser(config, ldapUsers[0]); if (!user) throw new BoxError(BoxError.BAD_FIELD, 'could not translate user');