@erebos/rpc-error
JSON-RPC error
Last updated a year ago by paul_lecam .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @erebos/rpc-error 
SYNC missed versions from official npm registry.

rpc-error

Error class and utilities for JSON-RPC errors.

Installation

yarn add @erebos/rpc-error

Usage

import RPCError, { parseError, methodNotFound } from '@erebos/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

Current Tags

  • 0.10.0                                ...           latest (a year ago)

1 Versions

  • 0.10.0                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |