-
Notifications
You must be signed in to change notification settings - Fork 4
Error Handling
Matthew B White edited this page Aug 19, 2021
·
3 revisions
From the chaincode perspective:
Node.js shows simply how the response to the peer is encoded.
type: fabprotos.protos.ChaincodeMessage.Type.ERROR,
payload: msg.payload,
txid: msg.txid,
channel_id : msg.channel_id
There is some variance on what the format of the payload is, and what the circumstances are that the type is chosen to be to either ERROR or COMPLETED
The payload format is not typed, but is often the the Response
structure.
// A response with a representation similar to an HTTP response that can
// be used within another message.
message Response {
// A status code that should follow the HTTP status codes.
int32 status = 1;
// A message associated with the response code.
string message = 2;
// A payload that can be used to include metadata with this response.
bytes payload = 3;
}
there are two helper functions that can be called to build this response.
const (
// OK constant - status code less than 400, endorser will endorse it.
// OK means init or invoke successfully.
OK = 200
// ERRORTHRESHOLD constant - status code greater than or equal to 400 will be considered an error and rejected by endorser.
ERRORTHRESHOLD = 400
// ERROR constant - default error value
ERROR = 500
)
// Success ...
func Success(payload []byte) pb.Response {
return pb.Response{
Status: OK,
Payload: payload,
}
}
// Error ...
func Error(msg string) pb.Response {
return pb.Response{
Status: ERROR,
Message: msg,
}
}
CM = ChaincodeMessage R = Reponse
go | java | node | |
---|---|---|---|
TX Invoked OK | CM.Type=COMPLETED | CM=COMPLETED | CM=COMPLETED |
CM.Payload=R.Status=OK | |||
CM.Payload=R.Payload=TX return value | |||
CM.Payload=R.Message=unset | |||
TX Invoked ERR | CM.Type=COMPLETED | ||
CM.Payload=R.status=ERROR | |||
CM.PayloadR.Payload=unset | |||
CM.PayloadR.Message=string | |||
PANIC | CM.Type=ERROR | ||
CM.Payload=[]bytes(err) |