Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@eeston/grpc-create-error
Advanced tools
Utility function that creates an Error suitable for gRPC responses
Utility function that creates an Error suitable for gRPC responses
This forked repository aims to provide a @grpc/grpc-js
compatable version of grpc-create-error. The original repository has a dependency that relies on grpc
which is no longer supported.
grpc-error - GRPCError
class that uses this module
grpc status codes - The grpc status codes.
npm install create-grpc-error --save
Error
Utility function that creates an Error suitable for gRPC responses. See tests for all examples
Kind: global function
Returns: Error
- The new Error
Param | Type | Description |
---|---|---|
message | String | Number | Error | Object | If String the error message If Number the error code If instanceof Error , the error to source data from. We still create a new Error instance, copy data from the passed error and assign / merge the rest of arguments. This can be used to mege metadata of existing error with additional metadata. If Object , assumed to be metadata, either plain object representation or actual grpc.Metadata instance. We use grpc-create-metadata module to create metadata for the return value. |
code | Number | Object | If Number the error code If Object , assumed to be metadata, either plain object representation or actual grpc.Metadata instance. We use grpc-create-metadata module to create metadata for the return value. |
metadata | Object | The error metadata. Either plain object representation or actual grpc.Metadata instance. We use grpc-create-metadata module to create metadata for the return value. |
Example (Using standard grpc status code)
const grpc = require('grpc')
const createGRPCError = require('create-grpc-error')
const err = createGRPCError('Ouch!', grpc.status.INVALID_ARGUMENT)
Example (Custom error with metadata)
const createGRPCError = require('create-grpc-error')
const err = createGRPCError('Boom', 2000, { ERROR_CODE: 'INVALID_TOKEN' })
console.log(err.message) // 'Boom'
console.log(err.code) // 2000
console.log(err.metadata instanceof grpc.Metadata) // true
console.log(err.metadata.getMap()) // { error_code: 'INVALID_TOKEN' }
Example (Source from error and merge metadatas)
const createGRPCError = require('create-grpc-error')
const existingError = new Error('Boom')
existingError.metadata = new grpc.Metadata()
existingError.metadata.add('foo', 'bar')
const err = createGRPCError(existingError, 2000, { ERROR_CODE: 'INVALID_TOKEN' })
console.log(err.message) // 'Boom'
console.log(err.code) // 2000
console.log(err.metadata instanceof grpc.Metadata) // true
console.log(err.metadata.getMap()) // { foo: 'bar', error_code: 'INVALID_TOKEN' }
Error
Actual function that does all the work. Same as createGRPCError but applies cretion to the existing error.
Kind: global function
Returns: Error
- See createGRPCError
description
Param | Type | Description |
---|---|---|
err | Error | The error to apply creation to |
message | String | Number | Error | Object | See createGRPCError description |
code | Number | Object | See createGRPCError description |
metadata | Object | See createGRPCError description |
Apache-2.0
FAQs
Utility function that creates an Error suitable for gRPC responses
We found that @eeston/grpc-create-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.