@mainframe/rpc-error
v0.4.0
Published
JSON-RPC error
Downloads
20
Keywords
Readme
rpc-error
Error class and utilities for JSON-RPC errors.
Installation
yarn add @mainframe/rpc-error
Usage
import RPCError, { parseError, methodNotFound } from '@mainframe/rpc-error'
const error1 = parseError()
const error2 = methodNotFound('get_user')
const error3 = new RPCError(-32600) // Invalid request
const error4 = new RPCError(1000, 'Custom app error', { user: 'alice' })
API
new RPCError()
Arguments
code: number
message?: string
: will be set based on thecode
when not provideddata?: T
: optional additional error data
.toObject()
Returns RPCErrorObject
RPCError.fromObject()
Creates a RPCError instance from a RPCErrorObject
.
Arguments
error: RPCErrorObject
Returns RPCError
instance
isServerError()
Arguments
code: number
Returns boolean
getErrorMessage()
Arguments
code: number
Returns string
parseError()
Arguments
data?: ?any
Returns RPCError
instance with code -32700
invalidRequest()
Arguments
data?: ?any
Returns RPCError
instance with code -32600
methodNotFound()
Arguments
data?: ?any
Returns RPCError
instance with code -32601
invalidParams()
Arguments
data?: ?any
Returns RPCError
instance with code -32602
internalError()
Arguments
data?: ?any
Returns RPCError
instance with code -32603
License
MIT