File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 1+ package serviceerror
2+
3+ import (
4+ "fmt"
5+
6+ "google.golang.org/grpc/codes"
7+ "google.golang.org/grpc/status"
8+ )
9+
10+ type (
11+ // Aborted represents an aborted error.
12+ Aborted struct {
13+ Message string
14+ st * status.Status
15+ }
16+ )
17+
18+ // NewAborted returns new Aborted error.
19+ func NewAborted (message string ) error {
20+ return & Aborted {
21+ Message : message ,
22+ }
23+ }
24+
25+ // NewAbortedf returns new Aborted error with formatted message.
26+ func NewAbortedf (format string , args ... any ) error {
27+ return & Aborted {
28+ Message : fmt .Sprintf (format , args ... ),
29+ }
30+ }
31+
32+ // Error returns string message.
33+ func (e * Aborted ) Error () string {
34+ return e .Message
35+ }
36+
37+ func (e * Aborted ) Status () * status.Status {
38+ if e .st != nil {
39+ return e .st
40+ }
41+ return status .New (codes .Aborted , e .Message )
42+ }
43+
44+ func newAborted (st * status.Status ) error {
45+ return & Aborted {
46+ Message : st .Message (),
47+ st : st ,
48+ }
49+ }
Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ func FromStatus(st *status.Status) error {
9494 case * failure.MultiOperationExecutionAborted :
9595 return newMultiOperationAborted (st )
9696 default :
97- // fall through to st.Err( )
97+ return newAborted ( st )
9898 }
9999 case codes .Internal :
100100 switch errDetails := errDetails .(type ) {
You can’t perform that action at this time.
0 commit comments