Skip to content

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 Aug 21, 2018
1 parent a1f1536 commit a172d78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/errors/src/index.js
Original file line number Diff line number Diff line change
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 packages/errors/test/index.test.js
Original file line number Diff line number Diff line change
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 a172d78

Please sign in to comment.