errors

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// Code is the HTTP-style status code (e.g., 400, 401, 500).
	Code int `json:"code,omitempty"`

	// Reason is a short error identifier (e.g., "InvalidParams", "Unauthorized").
	Reason string `json:"reason,omitempty"`

	// Message is a human-readable error description.
	Message string `json:"message,omitempty"`

	// Metadata holds additional key-value data about the error.
	Metadata map[string]string `json:"metadata,omitempty"`
}

Error represents an error with HTTP-style code, reason, and message.

func FromError

func FromError(err error) *Error

FromError converts an error to *Error. If the error is already an *Error, it returns it directly. Otherwise, it wraps it as an internal error.

func New

func New(code int, reason string, format string, args ...any) *Error

New creates a new Error with the given code, reason, and formatted message.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) JSONRPCCode

func (e *Error) JSONRPCCode() int

JSONRPCCode returns the JSON-RPC error code for this error.

func (*Error) WithMessage

func (e *Error) WithMessage(format string, args ...any) *Error

WithMessage sets the error message.

func (*Error) WithMetadata

func (e *Error) WithMetadata(md map[string]string) *Error

WithMetadata sets the error metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL