errors

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrParseError      = -32700
	ErrInvalidRequest  = -32600
	ErrMethodNotFound  = -32601
	ErrInvalidParams   = -32602
	ErrInternalError   = -32603
	ErrUnauthorized    = -32001
	ErrForbidden       = -32003
	ErrNotFound        = -32004
	ErrTimeout         = -32008
	ErrConflict        = -32009
	ErrTooManyRequests = -32029
)

tRPC error codes (TRPC_ERROR_CODES_BY_KEY)

View Source
const ErrBadRequest = ErrInvalidRequest

ErrBadRequest is an alias for ErrInvalidRequest. Both map to tRPC code -32600. Use ErrBadRequest for application-level validation errors; ErrInvalidRequest for protocol-level errors.

Variables

This section is empty.

Functions

func CodeName

func CodeName(code int) string

CodeName returns the string name for a tRPC error code.

func HTTPStatus

func HTTPStatus(code int) int

HTTPStatus returns the HTTP status code for a tRPC error code.

Types

type TRPCError

type TRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Cause   error  `json:"-"` // original error for logging; never sent to client
}

TRPCError represents a tRPC-compatible error.

func New

func New(code int, message string) *TRPCError

New creates a new TRPCError with the given code and message.

func Newf

func Newf(code int, format string, args ...interface{}) *TRPCError

Newf creates a new TRPCError with a formatted message.

func Wrap

func Wrap(err error, code int, message string) *TRPCError

Wrap creates a TRPCError that wraps an underlying error. The cause is preserved for logging but never sent to the client.

func Wrapf

func Wrapf(err error, code int, format string, args ...interface{}) *TRPCError

Wrapf creates a TRPCError that wraps an underlying error with a formatted message.

func (*TRPCError) Error

func (e *TRPCError) Error() string

func (*TRPCError) Unwrap

func (e *TRPCError) Unwrap() error

Unwrap returns the underlying cause, enabling errors.Is and errors.As.

Jump to

Keyboard shortcuts

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