errs

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 5 Imported by: 18

Documentation

Overview

Package errs API gateway framework error related definitions, related methods

Index

Constants

View Source
const (
	// Success status code
	Success = 0
	// ErrGatewayUnknown Distinguishing between unknown errors in the gateway and unknown error codes in trpc
	ErrGatewayUnknown = trpcpb.TrpcRetCode(999)

	// ErrWrongConfig Configuration error
	ErrWrongConfig = trpcpb.TrpcRetCode(1001)

	// ErrPathNotFound No route matched
	ErrPathNotFound = trpcpb.TrpcRetCode(1002)

	// ErrWrongContext Context type error (non-fasthttp context)
	ErrWrongContext = trpcpb.TrpcRetCode(1003)

	// ErrTargetServiceNotFound Failed to obtain the target server
	ErrTargetServiceNotFound = trpcpb.TrpcRetCode(1004)

	// ErrContextNoServiceVal Failed to obtain service information from the context
	ErrContextNoServiceVal = trpcpb.TrpcRetCode(1005)

	// ErrPluginConfigNotFound Failed to obtain plugin configuration from the context
	ErrPluginConfigNotFound = trpcpb.TrpcRetCode(1006)

	// ErrInvalidPluginConfig Plugin configuration error
	ErrInvalidPluginConfig = trpcpb.TrpcRetCode(1007)

	// ErrUpstreamRspErr upstream HTTP status code is not 200
	ErrUpstreamRspErr = trpcpb.TrpcRetCode(1008)

	// ErrInvalidReq Illegal request, protocol error, etc.
	ErrInvalidReq = trpcpb.TrpcRetCode(1009)

	// ErrUnSupportProtocol Unsupported protocol type
	ErrUnSupportProtocol = trpcpb.TrpcRetCode(1010)

	// ErrProtocolTrans Protocol conversion failed
	ErrProtocolTrans = trpcpb.TrpcRetCode(1011)

	// ErrConnClosed Connection pool closed
	ErrConnClosed = trpcpb.TrpcRetCode(1012)
)
View Source
const (
	// GatewayERRKey Reporting key for abnormal configuration loading to be used for monitoring and alerting
	GatewayERRKey = "trpc_gateway_report"
)

Variables

This section is empty.

Functions

func GetHTTPStatus

func GetHTTPStatus(trpcCode trpc.TrpcRetCode) int

GetHTTPStatus Obtaining the HTTP status code through tRPC error code

func IsSuccessHTTPStatus

func IsSuccessHTTPStatus(httpStatus int32) bool

IsSuccessHTTPStatus Determining if an HTTP status code indicates successful redirection

func Register

func Register[T trpc.TrpcRetCode](errCode T, httpStatus int32) error

Register Registering the mapping relationship between custom err codes and HTTP status codes, for example: in the authentication plugin, mapping a custom authentication failure err code to the HTTP 401 status code. Call it in the plugin's Setup method.

func RegisterSuccessHTTPStatus

func RegisterSuccessHTTPStatus(httpStatusList []int32)

RegisterSuccessHTTPStatus Registering successful HTTP status codes for redirection

func UnWrap

func UnWrap(e error) (*errs.Error, bool)

UnWrap Obtain the most original trpc error

func Wrap

func Wrap(e error, msg string) error

Wrap the error to use a unified log separator, refer to this article for the usage of the errors standard library: https://www.flysnow.org/2019/09/06/go1.13-error-wrapping.html

func Wrapf

func Wrapf(err error, format string, arg ...interface{}) error

Wrapf Wrap the error to use a unified log separator, with the ability to pass parameters

Types

This section is empty.

Jump to

Keyboard shortcuts

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