Hyperledger fabric Golang chaincode随消息发送错误代码

Hyperledger fabric Golang chaincode随消息发送错误代码,hyperledger-fabric,chaincode,Hyperledger Fabric,Chaincode,我还想使用shim.error函数向客户端应用程序发送错误消息以外的错误代码,但它只接受msg参数,如何执行?shim.error返回一个响应结构 func Error(msg string) pb.Response { return pb.Response{ Status: ERROR, Message: msg, } } 状态设置为ERROR const,定义为500。但您可以使用>=400的任何错误代码 因此,您可以自己构造响应并设置状态

我还想使用
shim.error
函数向客户端应用程序发送错误消息以外的错误代码,但它只接受
msg
参数,如何执行?

shim.error返回一个响应结构

func Error(msg string) pb.Response {
    return pb.Response{
        Status:  ERROR,
        Message: msg,
    }
}
状态设置为ERROR const,定义为500。但您可以使用>=400的任何错误代码

因此,您可以自己构造响应并设置状态代码,而不是使用错误函数

return pb.Response{
        Status:  404,
        Message: "Invoke method you wanted to trigger does not exist",
    } 
或者,您可以编写自己的错误函数,该函数还接受状态代码,并确保该代码在错误范围内

最后一个选项是使用响应的Payload属性,并在Payload中添加错误的详细信息,包括状态代码