53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// Errors
|
|
var (
|
|
ErrInvalidServer = errors.New("server is invalid")
|
|
ErrInvalidRequest = errors.New("request is invalid")
|
|
ErrInvalidParameter = errors.New("parameter is invalid")
|
|
ErrTestNotImplemented = errors.New("test path not implemented")
|
|
|
|
ErrMultiple = errors.New("Multiple errors in transaction")
|
|
ErrEmptyFrom = errors.New("from must not be empty")
|
|
ErrInvalidTo = errors.New("to must be a valid 32-byte address")
|
|
ErrEmptyName = errors.New("name must not be empty")
|
|
)
|
|
|
|
func toStatusError(src error) error {
|
|
/*__*/ if src == nil {
|
|
return src
|
|
} else if _, ok := src.(interface{ GRPCStatus() *status.Status }); ok {
|
|
return src
|
|
} else {
|
|
switch errors.Cause(src) {
|
|
/////////////////////////////////////////////////////////////////////
|
|
default:
|
|
return src
|
|
case ErrInvalidServer:
|
|
fallthrough
|
|
case ErrInvalidRequest:
|
|
return status.Error(codes.Internal, src.Error())
|
|
case ErrInvalidParameter:
|
|
return status.Error(codes.InvalidArgument, src.Error())
|
|
case ErrTestNotImplemented:
|
|
return status.Error(codes.Unimplemented, src.Error())
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
case ErrEmptyName:
|
|
fallthrough
|
|
case ErrEmptyFrom:
|
|
fallthrough
|
|
case ErrInvalidTo:
|
|
return status.Error(codes.InvalidArgument, src.Error())
|
|
case ErrMultiple:
|
|
return status.Error(codes.InvalidArgument, src.Error())
|
|
}
|
|
}
|
|
}
|