From 2b181378b5613f9bc855af24081837786e3ef6d4 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 7 Nov 2014 14:20:31 +0100 Subject: [PATCH] proper error handling, fixed #485 --- libjsqrc/main.js | 38 +++++++++++++++++++++----------------- libjsqrc/qt.js | 8 ++++---- libqethereum/QEthereum.cpp | 1 + 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/libjsqrc/main.js b/libjsqrc/main.js index 821de6382..b8c27060e 100644 --- a/libjsqrc/main.js +++ b/libjsqrc/main.js @@ -2,19 +2,19 @@ This file is part of ethereum.js. ethereum.js is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by + it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ethereum.js is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with ethereum.js. If not, see . */ -/** @file ethereum.js +/** @file main.js * @authors: * Marek Kotewicz * @date 2014 @@ -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) { @@ -218,7 +222,7 @@ var str = ""; var i = 0, l = hex.length; if (hex.substring(0, 2) == '0x') - i = 2; + i = 2; for(; i < l; i+=2) { var code = hex.charCodeAt(i) if(code == 0) { @@ -240,7 +244,7 @@ var hex = this.toHex(str); while(hex.length < pad*2) hex += "00"; - return "0x" + hex + return "0x" + hex; }, eth: { @@ -440,7 +444,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]; } } diff --git a/libjsqrc/qt.js b/libjsqrc/qt.js index f0312eb2f..aedd34236 100644 --- a/libjsqrc/qt.js +++ b/libjsqrc/qt.js @@ -2,19 +2,19 @@ This file is part of ethereum.js. ethereum.js is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by + it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ethereum.js is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with ethereum.js. If not, see . */ -/** @file ethereum.js +/** @file qt.js * @authors: * Marek Kotewicz * @date 2014 diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index 08165d9db..42e00958a 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -120,6 +120,7 @@ static QString formatOutput(QJsonObject const& _object) QJsonObject res; res["_id"] = _object["id"]; res["data"] = _object["result"]; + res["error"] = _object["error"]; return QString::fromUtf8(QJsonDocument(res).toJson()); }