RPC Errors
Purpose
Error class and utilities for JSON-RPC errors.
Installation
npm install @erebos/rpc-error
Usage
import {
RPCError,
createParseError,
createMethodNotFound,
} from '@erebos/rpc-error'
const error1 = createParseError()
const error2 = createMethodNotFound('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 = any
: 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
createParseError()
Arguments
data?: ?any
Returns RPCError
instance with code -32700
createInvalidRequest()
Arguments
data?: ?any
Returns RPCError
instance with code -32600
createMethodNotFound()
Arguments
data?: ?any
Returns RPCError
instance with code -32601
createInvalidParams()
Arguments
data?: ?any
Returns RPCError
instance with code -32602
createInternalError()
Arguments
data?: ?any
Returns RPCError
instance with code -32603