/
errors.go
77 lines (61 loc) · 1.67 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright 2021 IBM All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package client
import (
"fmt"
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/grpc/status"
)
type grpcError struct {
error
}
func (e *grpcError) GRPCStatus() *status.Status {
return status.Convert(e.error)
}
func (e *grpcError) Unwrap() error {
return e.error
}
func newTransactionError(err error, transactionID string) *TransactionError {
if err == nil {
return nil
}
return &TransactionError{
grpcError: &grpcError{err},
TransactionID: transactionID,
}
}
// TransactionError represents an error invoking a transaction. This is a gRPC status error.
type TransactionError struct {
*grpcError
TransactionID string
}
// EndorseError represents a failure endorsing a transaction proposal.
type EndorseError struct {
*TransactionError
}
// SubmitError represents a failure submitting an endorsed transaction to the orderer.
type SubmitError struct {
*TransactionError
}
// CommitStatusError represents a failure obtaining the commit status of a transaction.
type CommitStatusError struct {
*TransactionError
}
func newCommitError(transactionID string, code peer.TxValidationCode) error {
return &CommitError{
message: fmt.Sprintf("transaction %s failed to commit with status code %d (%s)", transactionID, int32(code), peer.TxValidationCode_name[int32(code)]),
TransactionID: transactionID,
Code: code,
}
}
// CommitError represents a transaction that fails to commit successfully.
type CommitError struct {
message string
TransactionID string
Code peer.TxValidationCode
}
func (e *CommitError) Error() string {
return e.message
}