From c369573b8caf71e45746079faba29bae4144dc8f Mon Sep 17 00:00:00 2001 From: Daniel Constantin Date: Mon, 8 May 2017 21:00:21 +0200 Subject: [PATCH] Allow data to be an array (#75) --- src/index.js | 2 +- test/index.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 25fb99b..eda4e46 100644 --- a/src/index.js +++ b/src/index.js @@ -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; diff --git a/test/index.test.js b/test/index.test.js index 19f9ac0..86b3d7c 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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'}]); + }); }); });