Skip to main content

Overview

The RequestError class represents errors that occur during JSON-RPC method execution in ACP connections. It follows the JSON-RPC 2.0 error object specification and provides static factory methods for creating standard error types.

Constructor

Creates a new RequestError with the specified error code, message, and optional additional data. Parameters:
  • code (number) - The JSON-RPC error code
  • message (string) - Human-readable error message
  • data (unknown, optional) - Additional error information

Properties

code

The numeric error code following JSON-RPC 2.0 conventions.

message

Human-readable description of the error.

data

Optional additional information about the error, such as validation details or context.

Static Factory Methods

parseError

Creates a parse error (code: -32700). Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. Parameters:
  • data (unknown, optional) - Additional error data
  • additionalMessage (string, optional) - Additional context to append to the error message
Returns: RequestError with code -32700 Example:

invalidRequest

Creates an invalid request error (code: -32600). The JSON sent is not a valid Request object. Parameters:
  • data (unknown, optional) - Additional error data
  • additionalMessage (string, optional) - Additional context to append to the error message
Returns: RequestError with code -32600 Example:

methodNotFound

Creates a method not found error (code: -32601). The method does not exist or is not available. Parameters:
  • method (string) - The method name that was not found
Returns: RequestError with code -32601 and the method name in data Example:

invalidParams

Creates an invalid params error (code: -32602). Invalid method parameter(s). Parameters:
  • data (unknown, optional) - Additional error data (often validation details)
  • additionalMessage (string, optional) - Additional context to append to the error message
Returns: RequestError with code -32602 Example:

internalError

Creates an internal error (code: -32603). Internal JSON-RPC error. Parameters:
  • data (unknown, optional) - Additional error data
  • additionalMessage (string, optional) - Additional context to append to the error message
Returns: RequestError with code -32603 Example:

authRequired

Creates an authentication required error (code: -32000). Parameters:
  • data (unknown, optional) - Additional error data
  • additionalMessage (string, optional) - Additional context to append to the error message
Returns: RequestError with code -32000 Example:

resourceNotFound

Creates a resource not found error (code: -32002). Resource, such as a file, was not found. Parameters:
  • uri (string, optional) - The URI of the missing resource
Returns: RequestError with code -32002 and URI in data (if provided) Example:

Instance Methods

toResult

Converts the RequestError to a JSON-RPC Result object with an error field. Returns: A Result object containing the error information Example:

toErrorResponse

Converts the RequestError to a JSON-RPC ErrorResponse object. Returns: An ErrorResponse object with code, message, and optional data Example:

Usage in Request Handlers

See Also