Can I send a custom Error message from server to client GRPC?
<p>I have created a simple GRPC server and  client .  </p>

<p>What i want to do is to create a custom error in the server and pass it to the client. My code looks as follows:</p>

<p><strong>Server.js</strong></p>

<pre><code>var error = require('error');

var PROTO_PATH = grpc.load(__dirname + '/proto/hello.proto');
var hello_proto = PROTO_PATH.hello;

function sayHello(call, callback) {

    try {
        var jsErr = new Error('MY_ERROR');
        jsErr.newStatus = 401;
        jsErr.newMessage = 'custom unAuthorized error';
        console.log(Object.getOwnPropertyNames(jsErr));
        console.log(jsErr);
        callback(jsErr);

    } catch(e) {
        callback(e);
    }
}

function sayHelloAgain(call, callback) {
    callback(null, {message: 'Hello Again ' + call.request.name});
}

function main() {

    var server = new grpc.Server();
    server.addProtoService(hello_proto.Hello.service, {sayHello: sayHello,sayHelloAgain: sayHelloAgain });
    server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
    server.start();
}

main();
</code></pre>

<p><strong>Client.js</strong></p>

<pre><code>var grpc = require('grpc');

var PROTO_PATH = grpc.load(__dirname + '/proto/hello.proto');
var hello_proto = PROTO_PATH.hello;

function main() {
    var client = new hello_proto.Hello('localhost:50051',grpc.credentials.createInsecure());
    var user;
    if (process.argv.length &gt;= 3) {
        user = process.argv[2];
    } else {
        user = 'world';
    }

    client.sayHello({name: user}, function(err, response) {

        console.log(Object.getOwnPropertyNames(err));
        console.log(err);
    });
}

main();
</code></pre>

<p>and my proto file </p>

<pre><code>syntax = "proto3";

package hello;

service Hello {
    rpc sayHello(sayHelloRequest) returns (sayHelloResponse) {}
    rpc sayHelloAgain(sayHelloRequest) returns (sayHelloResponse) {}
}


message sayHelloRequest {
    string name = 1;
}

message sayHelloResponse {
    string message = 1;
}
</code></pre>

<p>when i run the cient the result from each looks like this </p>

<p>Server .</p>

<pre><code>[ 'stack', 'message', 'newStatus', 'newMessage' ]
{ [Error: MY_ERROR] newStatus: 401, newMessage: 'custom unAutorized error' }
</code></pre>

<p>Client .</p>

<pre><code>[ 'stack', 'message', 'code', 'metadata' ]
{ [Error: MY_ERROR] code: 2, metadata: Metadata { _internal_repr: {} } }
</code></pre>

<p>So my created custom javascript error's <code>newStatus, newMessage</code> properties have removed and it has converted to GRPC standard error message . </p>

<p>My Questions are </p>

<ol>
<li>Is it possible to send a custom message to client ?</li>
<li>Can i create a GRPC error , not a javascript error ?</li>
<li>one way to send custom attributes to client is i think is add the custom data to <code>Metadata</code> . but i am also not sure how to do it . </li>
</ol>