@eeston/grpc-error

2.0.0 • Public • Published

grpc-error

Utility Error class suitable for gRPC error responses

Related

grpc-create-error - A helper function module that this class uses

grpc status codes - The grpc status codes.

Usage

const GRPCError = require('grpc-error')
const grpc = require('grpc')
const error = new GRPCError('Boom', grpc.status.INVALID_ARGUMENT)
const GRPCError = require('grpc-error')

const error = new GRPCError('Boom', 2000, { status_code: 'INVALID_TOKEN' )
console.log(err instanceof Error) // true
console.log(err.message) // 'Boom'
console.log(err.code) // 2000
console.log(err.metadata instanceof grpc.Metadata) // true
console.log(err.metadata.getMap()) // { status_code: 'INVALID_TOKEN' }
const GRPCError = require('grpc-error')

const error = new GRPCError('Boom', { status_code: 'INVALID_TOKEN' )
console.log(err instanceof Error) // true
console.log(err.message) // 'Boom'
console.log(err.metadata instanceof grpc.Metadata) // true
console.log(err.metadata.getMap()) // { status_code: 'INVALID_TOKEN' }

License

Apache-2.0

Package Sidebar

Install

npm i @eeston/grpc-error

Weekly Downloads

1

Version

2.0.0

License

Apache-2.0

Unpacked Size

18.3 kB

Total Files

8

Last publish

Collaborators

  • eeston