From f15f5fc4563460dd234a39b36d11c694f8b5f2f3 Mon Sep 17 00:00:00 2001 From: Eric Kryski Date: Sun, 17 Jul 2016 15:27:38 -0600 Subject: [PATCH] changing duplicate key error to feathers Conflict error. Closes #104 (#105) --- src/error-handler.js | 2 +- test/error-handler.test.js | 4 ++-- test/index.test.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/error-handler.js b/src/error-handler.js index b62cb232..c2d074a3 100644 --- a/src/error-handler.js +++ b/src/error-handler.js @@ -20,7 +20,7 @@ export default function errorHandler(error) { break; case 'MongoError': if (error.code === 11000) { - feathersError = new errors.BadRequest(error); + feathersError = new errors.Conflict(error); } else { feathersError = new errors.GeneralError(error); diff --git a/test/error-handler.test.js b/test/error-handler.test.js index 8968a33b..9e237c0b 100644 --- a/test/error-handler.test.js +++ b/test/error-handler.test.js @@ -100,12 +100,12 @@ describe('Feathers Mongoose Error Handler', () => { }).catch(done); }); - it('wraps a DuplicateKey error as a BadRequest', done => { + it('wraps a DuplicateKey error as a Conflict', done => { let e = Error('Mock Duplicate Key Error'); e.name = 'MongoError'; e.code = 11000; errorHandler(e).catch(error => { - expect(error).to.be.an.instanceof(errors.BadRequest); + expect(error).to.be.an.instanceof(errors.Conflict); done(); }).catch(done); }); diff --git a/test/index.test.js b/test/index.test.js index 215f7e03..d73694c1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -207,12 +207,12 @@ describe('Feathers Mongoose Service', () => { }); }); - it('returns a BadRequest when unique index is violated', function(done) { + it('returns a Conflict when unique index is violated', function(done) { pets.create({ type: 'cat', name: 'Bob' }) .then(() => pets.create({ type: 'cat', name: 'Bob' })) .then(() => done(new Error('Should not be successful'))) .catch(error => { - expect(error.name).to.equal('BadRequest'); + expect(error.name).to.equal('Conflict'); done(); }); });