Skip to content

Commit

Permalink
changing duplicate key error to feathers Conflict error. Closes #104 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ekryski authored Jul 17, 2016
1 parent fd64ac4 commit f15f5fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/error-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit f15f5fc

Please sign in to comment.