aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/ext
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-08-17 11:36:03 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-08-17 11:36:03 -0700
commit28c37b8856b952892a41e578b3ce1cc759255f08 (patch)
treec2d5987cd913a59ae33c48cf7a16f26452d2f208 /src/node/ext
parent2194cd8fd4d53a3333fbd0e7bc938e22210d23d2 (diff)
Added an inline C++ function to replace a deprecated nan function
Diffstat (limited to 'src/node/ext')
-rw-r--r--src/node/ext/call.cc4
-rw-r--r--src/node/ext/call.h13
-rw-r--r--src/node/ext/server.cc2
3 files changed, 16 insertions, 3 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index 705c80ffc1..1e76ea7194 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -619,7 +619,7 @@ NAN_METHOD(Call::StartBatch) {
call->wrapped_call, &ops[0], nops, new struct tag(
callback, op_vector.release(), resources), NULL);
if (error != GRPC_CALL_OK) {
- return NanThrowError("startBatch failed", error);
+ return NanThrowError(nanErrorWithCode("startBatch failed", error));
}
CompletionQueueAsyncWorker::Next();
NanReturnUndefined();
@@ -633,7 +633,7 @@ NAN_METHOD(Call::Cancel) {
Call *call = ObjectWrap::Unwrap<Call>(args.This());
grpc_call_error error = grpc_call_cancel(call->wrapped_call, NULL);
if (error != GRPC_CALL_OK) {
- return NanThrowError("cancel failed", error);
+ return NanThrowError(nanErrorWithCode("cancel failed", error));
}
NanReturnUndefined();
}
diff --git a/src/node/ext/call.h b/src/node/ext/call.h
index 6acda76197..ef6e5fcd21 100644
--- a/src/node/ext/call.h
+++ b/src/node/ext/call.h
@@ -51,6 +51,19 @@ namespace node {
using std::unique_ptr;
using std::shared_ptr;
+/**
+ * Helper function for throwing errors with a grpc_call_error value.
+ * Modified from the answer by Gus Goose to
+ * http://stackoverflow.com/questions/31794200.
+ */
+inline v8::Local<v8::Value> nanErrorWithCode(const char *msg,
+ grpc_call_error code) {
+ NanEscapableScope();
+ v8::Local<v8::Object> err = NanError(msg).As<v8::Object>();
+ err->Set(NanNew("code"), NanNew<v8::Uint32>(code));
+ return NanEscapeScope(err);
+}
+
v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array);
class PersistentHolder {
diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc
index 8e39644846..01217bce79 100644
--- a/src/node/ext/server.cc
+++ b/src/node/ext/server.cc
@@ -235,7 +235,7 @@ NAN_METHOD(Server::RequestCall) {
new struct tag(new NanCallback(args[0].As<Function>()), ops.release(),
shared_ptr<Resources>(nullptr)));
if (error != GRPC_CALL_OK) {
- return NanThrowError("requestCall failed", error);
+ return NanThrowError(nanErrorWithCode("requestCall failed", error));
}
CompletionQueueAsyncWorker::Next();
NanReturnUndefined();