-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-9849] Document status, multi, retry packages
Change-Id: I8c2d83022ed223b675f4a9f95992c1a6ba74481e Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package multi | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func Example() { | ||
errs := Errors{} | ||
errs = append(errs, fmt.Errorf("peer0 failed")) | ||
errs = append(errs, fmt.Errorf("peer1 failed")) | ||
|
||
// Multi errors implement the standard error interface and are returned as regular errors | ||
err := interface{}(errs).(error) | ||
|
||
// We can extract multi errors from a standard error | ||
errs, ok := err.(Errors) | ||
fmt.Println(ok) | ||
|
||
// And handle each error individually | ||
for _, e := range errs { | ||
fmt.Println(e) | ||
} | ||
|
||
// Output: | ||
// true | ||
// peer0 failed | ||
// peer1 failed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package status | ||
|
||
import "fmt" | ||
|
||
func Example() { | ||
// Status errors are returned for certain transient errors by clients in the SDK | ||
statusError := New(ClientStatus, EndorsementMismatch.ToInt32(), "proposal responses do not match", nil) | ||
|
||
// Status errors implement the standard error interface and are returned as regular errors | ||
err := interface{}(statusError).(error) | ||
|
||
// A user can extract status information from a status | ||
status, ok := FromError(err) | ||
fmt.Println(ok) | ||
fmt.Println(status.Group) | ||
fmt.Println(Code(status.Code)) | ||
fmt.Println(status.Message) | ||
|
||
// Output: | ||
// true | ||
// Client Status | ||
// ENDORSEMENT_MISMATCH | ||
// proposal responses do not match | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters