Base

JpiError

Base class for all errors defined by Jpi, as well as any application-defined errors. This class does not have its own code property, but does provide a getter for the code on instances, so codes only need to be defined on subclass constructors.

To create your own application-defined JSON-RPC error, inherit from this class and assign an integer code to the subclass's constructor. The code must be an integer greater than -32099, as specified by the JSON-RPC standard.

This class, as well as all other error classes in ths project, inherit from NaniError and may use any of the constructor arguments of that class. For more information, see Nani.

new JpiError()

Extends NaniError

Instance Members
code

JSON-RPC Standard

ParseError

Class for standard JSON-RPC parse errors.

new ParseError()

Extends JpiError

Static Members
code

InvalidRequestError

Class for standard JSON-RPC invalid request errors.

new InvalidRequestError()

Extends JpiError

Static Members
code

MethodNotFoundError

Class for standard JSON-RPC method not found errors.

new MethodNotFoundError()

Extends JpiError

Static Members
code

InvalidParamsError

Class for standard JSON-RPC invalid params errors.

new InvalidParamsError()

Extends JpiError

Static Members
code

InternalError

Class for standard JSON-RPC internal errors.

new InternalError()

Extends JpiError

Static Members
code

Jpi-Specific

ServerError

Class for generic Jpi server errors. Will be used by Jpi to wrap any error thrown by a middleware that is not a JpiError with an integer code.

To define your own server errors for your application, do not inherit from this class. Inherit from the base JpiError class instead.

new ServerError()

Extends JpiError

Static Members
code

Conversion Utils

toObject

Converts an Error instance-- along with its entire cause chain-- into a JSON-RPC-compliant error object. Objects will include message properties, as well as a data object that will include any and all properties supported by Nani. They will also include code properties, though they will be placed either in the data or at the top level based on a number of factors:

A code will appear in the top level of its object if and only if:

  • The error "is" a JpiError (see Nani.is)
  • The code is an integer.

In all other cases, codes will be included in the data object instead.

toObject(err: Error, includeStacks: boolean): Object
Parameters
err (Error) Error instance to convert.
includeStacks (boolean = false) Set to true to include stack traces in the results. Due to the performance penalty of accessing the stack property in V8, this should generally not be used in production environments.
Returns
Object: Created JSON-RPC error object.

fromObject

Converts a JSON-RPC Error object to an Error instance. Errors will be created with the standard Error constructor, but they will include all properties supported by Nani, as well as the code property.

There will be no stack frames on any Error created by this function, unless they are provided in the object, because there is otherwise no way to tell anything about where the error originally came from. If you plan on throwing any of these errors, you should wrap them with new errors to so you can have a useful stack trace.

fromObject(obj: Object): Error
Parameters
obj (Object) JSON-RPC error object.
Returns
Error: Created Error instance.