Documentation
¶
Index ¶
- Constants
- Variables
- func ClientInterceptor(ctx context.Context, method string, req interface{}, reply interface{}, ...) error
- func GetGRPCInterceptor(serviceID int) grpc.UnaryServerInterceptor
- func LoggingInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func New(code errCode, index int, message string) error
- func ToGRPC(err *Err) error
- type Err
- type ErrTemplate
Constants ¶
View Source
const ( ErrCodeBadRequest = errCode(400) ErrCodeForbidden = errCode(403) ErrCodeNotFound = errCode(404) ErrCodeNotAllowed = errCode(405) ErrCodeRequestTimeout = errCode(408) ErrCodeInternal = errCode(500) ErrCodeNotImplemented = errCode(501) ErrCodeBadGateway = errCode(502) ErrCodeUnknown = errCode(520) )
Variables ¶
View Source
var ( ErrUnknown = &Err{ Code: ErrCodeUnknown, Index: 0, Message: "UNKNOWN", } )
Functions ¶
func ClientInterceptor ¶
func ClientInterceptor( ctx context.Context, method string, req interface{}, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption, ) error
func GetGRPCInterceptor ¶
func GetGRPCInterceptor(serviceID int) grpc.UnaryServerInterceptor
func LoggingInterceptor ¶
func LoggingInterceptor( ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (resp interface{}, err error)
Types ¶
type Err ¶
type Err struct { Code errCode `json:"code"` // HTTP-коды, 400, 500 и т.д. Index int `json:"index"` // Шестизначный индекс ошибки, где первые две цифры - номер сервиса, остальные - номер ошибки в сервисе Message string `json:"message"` // Сообщение, которое принимают фронты или другие сервисы Params any `json:"params,omitempty"` // Дополнительные параметры }
Err заменяет ошибку для фронта
type ErrTemplate ¶
type ErrTemplate struct { Code errCode `json:"code"` // HTTP-коды, 400, 500 и т.д. Index int `json:"index"` // Шестизначный индекс ошибки, где первые две цифры - номер сервиса, остальные - номер ошибки в сервисе Message string `json:"message"` // Сообщение, которое принимают фронты или другие сервисы }
ErrTemplate - шаблон для ошибки, для которой дополнительно можно указать параметры в месте возникновения
func NewTemplate ¶
func NewTemplate(code errCode, index int, message string) *ErrTemplate
func (*ErrTemplate) New ¶
func (t *ErrTemplate) New(params any) error
Click to show internal directories.
Click to hide internal directories.