Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Latest commit

 

History

History

rpc-error

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

  1. code: number
  2. message?: string: will be set based on the code when not provided
  3. data?: T: optional additional error data

.toObject()

Returns RPCErrorObject

RPCError.fromObject()

Creates a RPCError instance from a RPCErrorObject.

Arguments

  1. error: RPCErrorObject

Returns RPCError instance

isServerError()

Arguments

  1. code: number

Returns boolean

getErrorMessage()

Arguments

  1. code: number

Returns string

parseError()

Arguments

  1. data?: ?any

Returns RPCError instance with code -32700

invalidRequest()

Arguments

  1. data?: ?any

Returns RPCError instance with code -32600

methodNotFound()

Arguments

  1. data?: ?any

Returns RPCError instance with code -32601

invalidParams()

Arguments

  1. data?: ?any

Returns RPCError instance with code -32602

internalError()

Arguments

  1. data?: ?any

Returns RPCError instance with code -32603

License

MIT