Browse Source

proper error handling, fixed #485

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
2b181378b5
  1. 38
      libjsqrc/main.js
  2. 8
      libjsqrc/qt.js
  3. 1
      libqethereum/QEthereum.cpp

38
libjsqrc/main.js

@ -2,19 +2,19 @@
This file is part of ethereum.js. This file is part of ethereum.js.
ethereum.js is free software: you can redistribute it and/or modify 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 the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ethereum.js is distributed in the hope that it will be useful, ethereum.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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 <http://www.gnu.org/licenses/>. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file ethereum.js /** @file main.js
* @authors: * @authors:
* Marek Kotewicz <marek@ethdev.com> * Marek Kotewicz <marek@ethdev.com>
* @date 2014 * @date 2014
@ -153,15 +153,15 @@
return {call: call, args: args}; return {call: call, args: args};
}).then(function (request) { }).then(function (request) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
web3.provider.send(request, function (result) { web3.provider.send(request, function (err, result) {
if (result || typeof result === "boolean") { if (!err) {
resolve(result); resolve(result);
return; return;
} }
reject(result); reject(err);
}); });
}); });
}).catch(function( err) { }).catch(function(err) {
console.error(err); console.error(err);
}); });
}; };
@ -173,8 +173,12 @@
var proto = {}; var proto = {};
proto.get = function () { proto.get = function () {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
web3.provider.send({call: property.getter}, function(result) { web3.provider.send({call: property.getter}, function(err, result) {
resolve(result); if (!err) {
resolve(result);
return;
}
reject(err);
}); });
}); });
}; };
@ -182,12 +186,12 @@
proto.set = function (val) { proto.set = function (val) {
return flattenPromise([val]).then(function (args) { return flattenPromise([val]).then(function (args) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
web3.provider.send({call: property.setter, args: args}, function (result) { web3.provider.send({call: property.setter, args: args}, function (err, result) {
if (result) { if (!err) {
resolve(result); resolve(result);
} else { return;
reject(result);
} }
reject(err);
}); });
}); });
}).catch(function (err) { }).catch(function (err) {
@ -218,7 +222,7 @@
var str = ""; var str = "";
var i = 0, l = hex.length; var i = 0, l = hex.length;
if (hex.substring(0, 2) == '0x') if (hex.substring(0, 2) == '0x')
i = 2; i = 2;
for(; i < l; i+=2) { for(; i < l; i+=2) {
var code = hex.charCodeAt(i) var code = hex.charCodeAt(i)
if(code == 0) { if(code == 0) {
@ -240,7 +244,7 @@
var hex = this.toHex(str); var hex = this.toHex(str);
while(hex.length < pad*2) while(hex.length < pad*2)
hex += "00"; hex += "00";
return "0x" + hex return "0x" + hex;
}, },
eth: { eth: {
@ -440,7 +444,7 @@
if(data._id) { if(data._id) {
var cb = web3._callbacks[data._id]; var cb = web3._callbacks[data._id];
if (cb) { if (cb) {
cb.call(this, data.data) cb.call(this, data.error, data.data);
delete web3._callbacks[data._id]; delete web3._callbacks[data._id];
} }
} }

8
libjsqrc/qt.js

@ -2,19 +2,19 @@
This file is part of ethereum.js. This file is part of ethereum.js.
ethereum.js is free software: you can redistribute it and/or modify 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 the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ethereum.js is distributed in the hope that it will be useful, ethereum.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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 <http://www.gnu.org/licenses/>. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file ethereum.js /** @file qt.js
* @authors: * @authors:
* Marek Kotewicz <marek@ethdev.com> * Marek Kotewicz <marek@ethdev.com>
* @date 2014 * @date 2014

1
libqethereum/QEthereum.cpp

@ -120,6 +120,7 @@ static QString formatOutput(QJsonObject const& _object)
QJsonObject res; QJsonObject res;
res["_id"] = _object["id"]; res["_id"] = _object["id"];
res["data"] = _object["result"]; res["data"] = _object["result"];
res["error"] = _object["error"];
return QString::fromUtf8(QJsonDocument(res).toJson()); return QString::fromUtf8(QJsonDocument(res).toJson());
} }

Loading…
Cancel
Save