Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bojand/grpc-error
Utility Error class suitable for gRPC error responses
https://github.com/bojand/grpc-error
grpc
Last synced: 10 days ago
JSON representation
Utility Error class suitable for gRPC error responses
- Host: GitHub
- URL: https://github.com/bojand/grpc-error
- Owner: bojand
- License: apache-2.0
- Created: 2016-12-30T16:54:27.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T10:25:49.000Z (almost 2 years ago)
- Last Synced: 2024-04-23T17:17:48.550Z (7 months ago)
- Topics: grpc
- Language: JavaScript
- Homepage: https://bojand.github.io/grpc-error
- Size: 155 KB
- Stars: 4
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-grpc - grpc-error - `GRPCError` class that wraps `create-grpc-error` (Language-Specific / Node.js)
README
# grpc-error
Utility Error class suitable for gRPC error responses
### Related
[grpc-create-error](https://github.com/bojand/grpc-create-error) - A helper function module that this class uses
[grpc status codes](https://grpc.io/grpc/node/grpc.html) - The grpc status codes.
## Usage
```js
const GRPCError = require('grpc-error')
const grpc = require('@grpc/grpc-js')
const error = new GRPCError('Boom', grpc.status.INVALID_ARGUMENT)
``````js
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' }
``````js
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