fmterr

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package fmterr is a set of tools for error.

Index

Constants

This section is empty.

Variables

View Source
var UnknownError = errors.New("unknown error")

Functions

func InitErrorHandler

func InitErrorHandler(cfg *conf.Configuration) error

InitErrorHandler pass to the error handler component

func ParseCodeMap

func ParseCodeMap(cfg *conf.Configuration) error

ParseCodeMap parse error code map from configuration. The configuration format is {int key} : {string}, for example:

1000: "error text"

func UnaryClientInterceptorInGin

func UnaryClientInterceptorInGin(_ *conf.Configuration) grpc.UnaryClientInterceptor

UnaryClientInterceptorInGin error handler for grpc client side in Gin. It will try to convert grpc status to gin.Error.

func UnaryServerInterceptor

func UnaryServerInterceptor(cfg *conf.Configuration) grpc.UnaryServerInterceptor

UnaryServerInterceptor error handler for grpc server side

func WrapperGrpcStatus

func WrapperGrpcStatus(err error) error

WrapperGrpcStatus wrap grpc error to pass to client.

Types

type Error

type Error gin.Error

Error is a wrapper for gin.Error

func Code

func Code(code uint64) *Error

Code create a new error by code only

func Codef

func Codef(code uint64, kvs ...any) *Error

Codef create a new error by code and args. args is a list of key value pairs, key is string, value is any. length of kvs equals 1 is meaning the error message.

func Codel

func Codel(code uint64, a ...any) *Error

Codel create a new error by code and args. args set to Meta will use int key.

func New

func New(code uint64, err error) *Error

New create a new error

func Newf

func Newf(code uint64, format string, a ...any) *Error

Newf create a new error

func (*Error) Code

func (e *Error) Code() gin.ErrorType

Code return the error code

func (*Error) Error

func (e *Error) Error() string

Error implement Error interface

func (*Error) JSON

func (e *Error) JSON() any

JSON creates a properly formatted JSON

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error, to allow interoperability with errors.Is(), errors.As() and errors.Unwrap()

Jump to

Keyboard shortcuts

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