Documentation ¶
Overview ¶
Package errs API gateway framework error related definitions, related methods
Index ¶
- Constants
- func GetHTTPStatus(trpcCode trpc.TrpcRetCode) int
- func IsSuccessHTTPStatus(httpStatus int32) bool
- func Register[T trpc.TrpcRetCode](errCode T, httpStatus int32) error
- func RegisterSuccessHTTPStatus(httpStatusList []int32)
- func UnWrap(e error) (*errs.Error, bool)
- func Wrap(e error, msg string) error
- func Wrapf(err error, format string, arg ...interface{}) error
Constants ¶
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) )
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 ¶
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 Wrap ¶
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
Types ¶
This section is empty.