Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Allow data to be an array (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelwhisperer authored and daffl committed May 8, 2017
1 parent 7159198 commit c369573
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -27,7 +27,7 @@ function FeathersError (msg, name, code, className, data) {
// NOTE(EK): To make sure that we are not messing
// with immutable data, just make a copy.
// https://github.com/feathersjs/feathers-errors/issues/19
newData = Object.assign({}, data);
newData = JSON.parse(JSON.stringify(data));

if (newData.errors) {
errors = newData.errors;
Expand Down
14 changes: 14 additions & 0 deletions test/index.test.js
Expand Up @@ -286,5 +286,19 @@ describe('feathers-errors', () => {
assert.equal(error.data.errors, undefined);
assert.deepEqual(error.data, {foo: 'bar'});
});

it('allows arrays as data', () => {
var data = [
{
hello: 'world'
}
];
data.errors = 'Invalid input';

var error = new errors.GeneralError('Custom Error', data);
assert.equal(error.data.errors, undefined);
assert.ok(Array.isArray(error.data));
assert.deepEqual(error.data, [{hello: 'world'}]);
});
});
});

0 comments on commit c369573

Please sign in to comment.