Files
bl/common/serialize/go-jsonrpc/errors.go
昔念 83ecb90baf refactor(project): 重构项目并更新依赖
- 更新 README.md 中的项目结构说明
- 添加 pprof 性能分析工具的使用说明
- 更新 build.bat 文件,增加 proto 文件编译命令
- 升级 go-logr/logr 依赖至 v1.3.0
- 降级 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc 依赖至 v1.16.0
- 降级 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp 依赖至 v1.16.0
- 升级 go.opentelemetry.io/otel/trace 依赖至 v1.20.0
- 移除 logic/main.go 中的冗余代码
- 重构 logic/server.go 中的 Start 函数
- 更新 login/main.go 文件
2025-07-06 17:05:10 +08:00

66 lines
1.1 KiB
Go

package jsonrpc
import (
"encoding/json"
"errors"
"reflect"
)
const eTempWSError = -1111111
type RPCConnectionError struct {
err error
}
func (e *RPCConnectionError) Error() string {
if e.err != nil {
return e.err.Error()
}
return "RPCConnectionError"
}
func (e *RPCConnectionError) Unwrap() error {
if e.err != nil {
return e.err
}
return errors.New("RPCConnectionError")
}
type Errors struct {
byType map[reflect.Type]ErrorCode
byCode map[ErrorCode]reflect.Type
}
type ErrorCode int
const FirstUserCode = 2
func NewErrors() Errors {
return Errors{
byType: map[reflect.Type]ErrorCode{},
byCode: map[ErrorCode]reflect.Type{
-1111111: reflect.TypeOf(&RPCConnectionError{}),
},
}
}
func (e *Errors) Register(c ErrorCode, typ interface{}) {
rt := reflect.TypeOf(typ).Elem()
if !rt.Implements(errorType) {
panic("can't register non-error types")
}
e.byType[rt] = c
e.byCode[c] = rt
}
type marshalable interface {
json.Marshaler
json.Unmarshaler
}
type RPCErrorCodec interface {
FromJSONRPCError(JSONRPCError) error
ToJSONRPCError() (JSONRPCError, error)
}