From dcdbbe54229ad741ca1dcd546b50f7069d23fff0 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 23 Feb 2015 17:40:18 -0800 Subject: [PATCH 1/2] Return error status as actual errors to client callbacks --- src/client.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index aaa7be79..54b8dbdc 100644 --- a/src/client.js +++ b/src/client.js @@ -245,7 +245,9 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { return; } if (response.status.code !== grpc.status.OK) { - callback(response.status); + var error = new Error(response.status.details); + error.code = response.status.code; + callback(error); return; } emitter.emit('status', response.status); @@ -314,7 +316,9 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { return; } if (response.status.code !== grpc.status.OK) { - callback(response.status); + var error = new Error(response.status.details); + error.code = response.status.code; + callback(error); return; } stream.emit('status', response.status); From 5c13ed40a95e435a2cd54f560a3abd7251e045e1 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 23 Feb 2015 17:44:21 -0800 Subject: [PATCH 2/2] Fixed old lint errors --- examples/pubsub/pubsub_demo.js | 6 +++++- examples/route_guide_client.js | 6 +++++- examples/route_guide_server.js | 10 +++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/pubsub/pubsub_demo.js b/examples/pubsub/pubsub_demo.js index a9b6acbd..94d2002d 100644 --- a/examples/pubsub/pubsub_demo.js +++ b/examples/pubsub/pubsub_demo.js @@ -27,6 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +'use strict'; + var async = require('async'); var fs = require('fs'); var GoogleAuth = require('googleauth'); @@ -270,7 +272,9 @@ function main(callback) { if (require.main === module) { main(function(err) { - if (err) throw err; + if (err) { + throw err; + } }); } diff --git a/examples/route_guide_client.js b/examples/route_guide_client.js index d4c083a6..425a94ee 100644 --- a/examples/route_guide_client.js +++ b/examples/route_guide_client.js @@ -27,6 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +'use strict'; + var async = require('async'); var fs = require('fs'); var parseArgs = require('minimist'); @@ -110,7 +112,9 @@ function runRecordRoute(callback) { string: 'db_path' }); fs.readFile(path.resolve(argv.db_path), function(err, data) { - if (err) callback(err); + if (err) { + callback(err); + } var feature_list = JSON.parse(data); var num_points = 10; diff --git a/examples/route_guide_server.js b/examples/route_guide_server.js index 0d3b5851..8970dd65 100644 --- a/examples/route_guide_server.js +++ b/examples/route_guide_server.js @@ -27,6 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +'use strict'; + var fs = require('fs'); var parseArgs = require('minimist'); var path = require('path'); @@ -163,7 +165,7 @@ function recordRoute(call, callback) { } /* For each point after the first, add the incremental distance from the * previous point to the total distance value */ - if (previous != null) { + if (previous !== null) { distance += getDistance(previous, point); } previous = point; @@ -173,7 +175,7 @@ function recordRoute(call, callback) { point_count: point_count, feature_count: feature_count, // Cast the distance to an integer - distance: distance|0, + distance: Math.floor(distance), // End the timer elapsed_time: process.hrtime(start_time)[0] }); @@ -240,7 +242,9 @@ if (require.main === module) { string: 'db_path' }); fs.readFile(path.resolve(argv.db_path), function(err, data) { - if (err) throw err; + if (err) { + throw err; + } feature_list = JSON.parse(data); routeServer.listen(); });