From 06ab33343f3b29799c7051ca0043cb3d97083d05 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 13 Jan 2017 14:15:31 -0800 Subject: [PATCH] Errors needs to use APIError. --- errors.js | 2 +- models/user.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/errors.js b/errors.js index 6cdc7425a..1b26e7170 100644 --- a/errors.js +++ b/errors.js @@ -54,7 +54,7 @@ const ErrEmailTaken = new APIError('Email address already in use', { status: 400 }); -const ErrDisplayTaken = new Error('Display name already in use', { +const ErrDisplayTaken = new APIError('Display name already in use', { translation_key: 'DISPLAYNAME_IN_USE', status: 400 }); diff --git a/models/user.js b/models/user.js index b0ead1c5a..a0ca34d7a 100644 --- a/models/user.js +++ b/models/user.js @@ -383,8 +383,7 @@ UserService.createLocalUser = (email, password, displayName) => { user.save((err) => { if (err) { if (err.code === 11000) { - const regex = new RegExp('displayName', 'g'); - if (regex.exec(err.message)[0] === 'displayName') { + if (err.message.match('displayName')) { return reject(errors.ErrDisplayTaken); } return reject(errors.ErrEmailTaken);