errors

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 15 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 pbrpc.Error

An internal Error details

func BadGateway

func BadGateway(opts ...Option) *Error

(#502) BAD_GATEWAY

 New(
	Status("BAD_GATEWAY"),
	Code(http.StatusBadGateway),
	opts...,
)

func BadRequest

func BadRequest(opts ...Option) *Error

(#400) BAD_REQUEST

 New(
	Status("BAD_REQUEST"),
	Code(http.StatusBadRequest),
	opts...,
)

func Errorf

func Errorf(message string, args ...any) *Error

Errorf

func Forbidden

func Forbidden(opts ...Option) *Error

(#403) FORBIDDEN

 New(
	Status("FORBIDDEN"),
	Code(http.StatusForbidden),
	opts...,
)

func FromError

func FromError(src error) (dst *Error, ok bool)

FromError type conversion method

func FromProto

func FromProto(src *pbrpc.Error) *Error

FromProto type conversion method

func FromStatus

func FromStatus(src *status.Status) (dst *Error, ok bool)

FromStatus type conversion method

func Internal

func Internal(opts ...Option) *Error

(#500) INTERNAL

 New(
	Status("INTERNAL"),
	Code(http.StatusInternalServerError),
	opts...,
)

func New

func New(opts ...Option) (err *Error)

New Error with Options..

func NotFound

func NotFound(opts ...Option) *Error

(#404) NOT_FOUND

 New(
	Status("NOT_FOUND"),
	Code(http.StatusNotFound),
	opts...,
)

func Parse

func Parse(message string) (dst *Error, ok bool)

Parse tries to parse a JSON string into an error. If that fails, it will set the given string as the error detail.

func Unauthorized

func Unauthorized(opts ...Option) *Error

(#401) UNAUTHORIZED

 New(
	Status("UNAUTHORIZED"),
	Code(http.StatusUnauthorized),
	opts...,
)

func (*Error) Error

func (e *Error) Error() string

Error implements Go error interface

func (*Error) GRPCStatus

func (e *Error) GRPCStatus() *status.Status

GRPCStatus returns the [grpc.Status] represented by [e]. Compatibility for grpc/status.FromError() method.

func (*Error) LogValue

func (e *Error) LogValue() slog.Value

func (*Error) Proto

func (e *Error) Proto() *pbrpc.Error

Proto returns [e] as an rpcpb.Error proto message.

func (*Error) ProtoAny

func (e *Error) ProtoAny() (*anypb.Any, error)

ProtoAny encodes [e] into [protobuf.Any] message structure

func (*Error) String

func (e *Error) String() string

type Option

type Option func(err *Error)

Option to setup Error details

func Code

func Code(code int32) Option

Error.Code number Option

func Message

func Message(form string, args ...any) Option

Error.Message format Option

func Status

func Status(code string) Option

Error.Status code Option

Jump to

Keyboard shortcuts

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