From 0d6479e1d63598baed0b0c41d4dd8ff9f7ecc449 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 7 Nov 2014 14:03:46 +0100 Subject: [PATCH 1/3] proper error handling proposal --- httprpc.js | 5 +++-- main.js | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/httprpc.js b/httprpc.js index ef29133..e738e1f 100644 --- a/httprpc.js +++ b/httprpc.js @@ -40,7 +40,8 @@ return { _id: object.id, - data: object.result + data: object.result, + error: object.error }; }; @@ -70,7 +71,7 @@ var self = this; this.sendRequest(payload, function (request) { var parsed = JSON.parse(request.responseText); - if (parsed.result instanceof Array ? parsed.result.length === 0 : !parsed.result) { + if (parsed.error || (parsed.result instanceof Array ? parsed.result.length === 0 : !parsed.result)) { return; } self.handlers.forEach(function (handler) { diff --git a/main.js b/main.js index ee98d55..1c544ef 100644 --- a/main.js +++ b/main.js @@ -153,15 +153,15 @@ return {call: call, args: args}; }).then(function (request) { return new Promise(function (resolve, reject) { - web3.provider.send(request, function (result) { - if (result || typeof result === "boolean") { + web3.provider.send(request, function (err, result) { + if (!err) { resolve(result); return; } - reject(result); + reject(err); }); }); - }).catch(function( err) { + }).catch(function(err) { console.error(err); }); }; @@ -173,8 +173,12 @@ var proto = {}; proto.get = function () { return new Promise(function(resolve, reject) { - web3.provider.send({call: property.getter}, function(result) { - resolve(result); + web3.provider.send({call: property.getter}, function(err, result) { + if (!err) { + resolve(result); + return + } + reject(err); }); }); }; @@ -182,12 +186,12 @@ proto.set = function (val) { return flattenPromise([val]).then(function (args) { return new Promise(function (resolve) { - web3.provider.send({call: property.setter, args: args}, function (result) { - if (result) { + web3.provider.send({call: property.setter, args: args}, function (err, result) { + if (!err) { resolve(result); - } else { - reject(result); + return } + reject(err); }); }); }).catch(function (err) { @@ -438,7 +442,7 @@ if(data._id) { var cb = web3._callbacks[data._id]; if (cb) { - cb.call(this, data.data) + cb.call(this, data.error, data.data) delete web3._callbacks[data._id]; } } From e3ad9be4c8053c18ed30775d62692f6fe91b1451 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 7 Nov 2014 14:07:01 +0100 Subject: [PATCH 2/3] missing semicolons --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 1c544ef..34b059f 100644 --- a/main.js +++ b/main.js @@ -176,7 +176,7 @@ web3.provider.send({call: property.getter}, function(err, result) { if (!err) { resolve(result); - return + return; } reject(err); }); @@ -189,7 +189,7 @@ web3.provider.send({call: property.setter, args: args}, function (err, result) { if (!err) { resolve(result); - return + return; } reject(err); }); From a2d8b8928949c589ad0282fbb1b9abf783f53c98 Mon Sep 17 00:00:00 2001 From: Marian Oancea Date: Sun, 9 Nov 2014 21:30:27 +0200 Subject: [PATCH 3/3] Added npm version --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4ffda9e..16cc2b1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is the Ethereum compatible JavaScript API using `Promise`s which implements the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC) spec. It's available on npm as a node module and also for bower and component as an embeddable js -[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6] +[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url] [![dev dependency status][dep-dev-image]][dep-dev-url] [![browser support](https://ci.testling.com/cubedro/ethereum.js.png)](https://ci.testling.com/cubedro/ethereum.js) @@ -69,9 +69,11 @@ go get github.com/ethereum/go-ethereum/ethereum ethereum -ws -loglevel=4 ``` -[1]: https://travis-ci.org/cubedro/ethereum.js.svg -[2]: https://travis-ci.org/cubedro/ethereum.js -[3]: https://david-dm.org/cubedro/ethereum.js.svg -[4]: https://david-dm.org/cubedro/ethereum.js -[5]: https://david-dm.org/cubedro/ethereum.js/dev-status.svg -[6]: https://david-dm.org/cubedro/ethereum.js#info=devDependencies \ No newline at end of file +[npm-image]: https://badge.fury.io/js/ethereum.js.png +[npm-url]: https://npmjs.org/package/ethereum.js +[travis-image]: https://travis-ci.org/cubedro/ethereum.js.svg +[travis-url]: https://travis-ci.org/cubedro/ethereum.js +[dep-image]: https://david-dm.org/cubedro/ethereum.js.svg +[dep-url]: https://david-dm.org/cubedro/ethereum.js +[dep-dev-image]: https://david-dm.org/cubedro/ethereum.js/dev-status.svg +[dep-dev-url]: https://david-dm.org/cubedro/ethereum.js#info=devDependencies \ No newline at end of file