Ninja Pumpkin Mutants

    @mainframe/rpc-error
    TypeScript icon, indicating that this package has built-in type declarations

    0.4.0 • Public • Published

    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

    Keywords

    none

    Install

    npm i @mainframe/rpc-error

    DownloadsWeekly Downloads

    1

    Version

    0.4.0

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    6

    Last publish

    Collaborators

    • aclarke
    • diogoperillo
    • howleysv
    • mosic
    • paul_lecam
    • sarahwiley