create-grpc-error
Utility function that creates an Error suitable for gRPC responses
Related
grpc-error - GRPCError
class that uses this module
API
Error
createGRPCError(message, code, metadata) ⇒ 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
const createGRPCError = const err = console // 'Boom'console // 2000console // trueconsole // { error_code: 'INVALID_TOKEN' }
Example (Source from error and merge metadatas)
const createGRPCError = const existingError = 'Boom'existingErrormetadata = existingErrormetadata const err = console // 'Boom'console // 2000console // trueconsole // { foo: 'bar', error_code: 'INVALID_TOKEN' }
Error
applyCreate(err, message, code, metadata) ⇒ 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 |
License
Apache-2.0