diff --git a/src/api/block.js b/src/api/block.js index 2d8bc7b12..8a6ec4529 100644 --- a/src/api/block.js +++ b/src/api/block.js @@ -8,7 +8,11 @@ module.exports = (send) => { stat: argCommand(send, 'block/stat'), put (file, cb) { if (Array.isArray(file)) { - return cb(null, new Error('block.put() only accepts 1 file')) + let err = new Error('block.put() only accepts 1 file') + if (typeof cb !== 'function' && typeof Promise !== 'undefined') { + return new Promise((resolve, reject) => reject(err)) + } + return cb(err) } return send('block/put', null, null, file, cb) } diff --git a/test/api/block.spec.js b/test/api/block.spec.js index d2873f38b..3851b09e4 100644 --- a/test/api/block.spec.js +++ b/test/api/block.spec.js @@ -8,6 +8,12 @@ describe('.block', () => { const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' const blorb = Buffer('blorb') + it('returns an error when putting an array of files', () => { + return apiClients.a.block.put([blorb, blorb], (err) => { + expect(err).to.be.an.instanceof(Error) + }) + }) + it('block.put', (done) => { apiClients.a.block.put(blorb, (err, res) => { expect(err).to.not.exist @@ -40,6 +46,13 @@ describe('.block', () => { }) describe('promise', () => { + it('returns an error when putting an array of files', () => { + return apiClients.a.block.put([blorb, blorb]) + .catch((err) => { + expect(err).to.be.an.instanceof(Error) + }) + }) + it('block.put', () => { return apiClients.a.block.put(blorb) .then((res) => {