@visiperf/visigrpc

1.0.1 • Public • Published

gRPC helpers, middlewares ... for Node.JS

Package @visiperf/visigrpc provide some functions to help you making a gRPC server. Errors logged on Sentry, HTTP status to gRPC code, ... Everything is made to assist you :)

Table of contents

Install

Use npm to install this package.

npm install --save @visiperf/visigrpc

Usage

Status

Error

The error(code, msg) function is used to return a gRPC error and log it into Sentry.

const grpc = require('grpc');
const sentry = require('@sentry/node');
const status = require('@visiperf/visigrpc/status');

sentry.init({ ... });

...

// your gRPC server implementation ...

...

function sayHello(call, callback) {
  callback(status.error(grpc.status.UNIMPLEMENTED, 'implement me'));
}
IMPORTANT : Only UNKNOWN, INTERNAL and DATA_LOSS errors will be reported in Sentry !

gRPC code from HTTP status

If you make an HTTP request, you can use the grpcCodeFromHttpStatus(status) func to convert HTTP status code in response to gRPC code.

const status = require('@visiperf/visigrpc/status');

let code = status.grpcCodeFromHttpStatus(403); // http status -> 403 (Forbidden)

// code -> 7 (grpc.status.PERMISSION_DENIED)

References

Package Sidebar

Install

npm i @visiperf/visigrpc

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

3.16 kB

Total Files

3

Last publish

Collaborators

  • cdegrel
  • caroline-pgt
  • ranout
  • jasseem-vp