Skip to content
Snippets Groups Projects
Commit 0db579d1 authored by Tim Emiola's avatar Tim Emiola
Browse files

Merge pull request #1505 from murgatroid99/node_status_error_event

Added error events on client streams when the server is streaming
parents b1f31048 40a4e862
No related branches found
No related tags found
No related merge requests found
...@@ -260,8 +260,8 @@ function cancelAfterFirstResponse(client, done) { ...@@ -260,8 +260,8 @@ function cancelAfterFirstResponse(client, done) {
call.on('data', function(data) { call.on('data', function(data) {
call.cancel(); call.cancel();
}); });
call.on('status', function(status) { call.on('error', function(error) {
assert.strictEqual(status.code, grpc.status.CANCELLED); assert.strictEqual(error.code, grpc.status.CANCELLED);
done(); done();
}); });
} }
......
{ {
"name": "grpc", "name": "grpc",
"version": "0.6.2", "version": "0.7.0",
"author": "Google Inc.", "author": "Google Inc.",
"description": "gRPC Library for Node", "description": "gRPC Library for Node",
"homepage": "http://www.grpc.io/", "homepage": "http://www.grpc.io/",
......
...@@ -245,6 +245,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { ...@@ -245,6 +245,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
if (response.status.code !== grpc.status.OK) { if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details); var error = new Error(response.status.details);
error.code = response.status.code; error.code = response.status.code;
error.metadata = response.status.metadata;
callback(error); callback(error);
return; return;
} }
...@@ -316,6 +317,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { ...@@ -316,6 +317,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) {
if (response.status.code !== grpc.status.OK) { if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details); var error = new Error(response.status.details);
error.code = response.status.code; error.code = response.status.code;
error.metadata = response.status.metadata;
callback(error); callback(error);
return; return;
} }
...@@ -382,6 +384,13 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { ...@@ -382,6 +384,13 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) {
throw err; throw err;
} }
stream.emit('status', response.status); stream.emit('status', response.status);
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
error.metadata = response.status.metadata;
stream.emit('error', error);
return;
}
}); });
}); });
return stream; return stream;
...@@ -440,6 +449,13 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { ...@@ -440,6 +449,13 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) {
throw err; throw err;
} }
stream.emit('status', response.status); stream.emit('status', response.status);
if (response.status.code !== grpc.status.OK) {
var error = new Error(response.status.details);
error.code = response.status.code;
error.metadata = response.status.metadata;
stream.emit('error', error);
return;
}
}); });
}); });
return stream; return stream;
......
...@@ -130,8 +130,7 @@ describe('Math client', function() { ...@@ -130,8 +130,7 @@ describe('Math client', function() {
}); });
call.write({dividend: 7, divisor: 0}); call.write({dividend: 7, divisor: 0});
call.end(); call.end();
call.on('status', function checkStatus(status) { call.on('error', function checkStatus(status) {
assert.notEqual(status.code, grpc.status.OK);
done(); done();
}); });
}); });
......
...@@ -278,9 +278,8 @@ describe('Trailing metadata', function() { ...@@ -278,9 +278,8 @@ describe('Trailing metadata', function() {
it('should be present when a server stream call fails', function(done) { it('should be present when a server stream call fails', function(done) {
var call = client.serverStream({error: true}); var call = client.serverStream({error: true});
call.on('data', function(){}); call.on('data', function(){});
call.on('status', function(status) { call.on('error', function(error) {
assert.notStrictEqual(status.code, grpc.status.OK); assert.deepEqual(error.metadata.metadata, ['yes']);
assert.deepEqual(status.metadata.metadata, ['yes']);
done(); done();
}); });
}); });
...@@ -302,9 +301,8 @@ describe('Trailing metadata', function() { ...@@ -302,9 +301,8 @@ describe('Trailing metadata', function() {
call.write({error: true}); call.write({error: true});
call.end(); call.end();
call.on('data', function(){}); call.on('data', function(){});
call.on('status', function(status) { call.on('error', function(error) {
assert.notStrictEqual(status.code, grpc.status.OK); assert.deepEqual(error.metadata.metadata, ['yes']);
assert.deepEqual(status.metadata.metadata, ['yes']);
done(); done();
}); });
}); });
...@@ -345,16 +343,16 @@ describe('Cancelling surface client', function() { ...@@ -345,16 +343,16 @@ describe('Cancelling surface client', function() {
}); });
it('Should correctly cancel a server stream call', function(done) { it('Should correctly cancel a server stream call', function(done) {
var call = client.fib({'limit': 5}); var call = client.fib({'limit': 5});
call.on('status', function(status) { call.on('error', function(error) {
assert.strictEqual(status.code, surface_client.status.CANCELLED); assert.strictEqual(error.code, surface_client.status.CANCELLED);
done(); done();
}); });
call.cancel(); call.cancel();
}); });
it('Should correctly cancel a bidi stream call', function(done) { it('Should correctly cancel a bidi stream call', function(done) {
var call = client.divMany(); var call = client.divMany();
call.on('status', function(status) { call.on('error', function(error) {
assert.strictEqual(status.code, surface_client.status.CANCELLED); assert.strictEqual(error.code, surface_client.status.CANCELLED);
done(); done();
}); });
call.cancel(); call.cancel();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment