@@ -56,35 +56,18 @@ func (m *sqlStore) Close() {
56
56
func (m * sqlStore ) txExecute (ctx context.Context , operation string , f func (tx sqlplugin.Tx ) error ) error {
57
57
tx , err := m .db .BeginTx (ctx )
58
58
if err != nil {
59
- return & types.InternalServiceError {
60
- Message : fmt .Sprintf ("%s failed. Failed to start transaction. Error: %v" , operation , err ),
61
- }
59
+ return convertCommonErrors (m .db , operation , "Failed to start transaction." , err )
62
60
}
63
61
err = f (tx )
64
62
if err != nil {
65
63
rollBackErr := tx .Rollback ()
66
64
if rollBackErr != nil {
67
65
m .logger .Error ("transaction rollback error" , tag .Error (rollBackErr ))
68
66
}
69
-
70
- switch err .(type ) {
71
- case * persistence.ConditionFailedError ,
72
- * persistence.CurrentWorkflowConditionFailedError ,
73
- * types.InternalServiceError ,
74
- * persistence.WorkflowExecutionAlreadyStartedError ,
75
- * types.DomainAlreadyExistsError ,
76
- * persistence.ShardOwnershipLostError :
77
- return err
78
- default :
79
- return & types.InternalServiceError {
80
- Message : fmt .Sprintf ("%v: %v" , operation , err ),
81
- }
82
- }
67
+ return convertCommonErrors (m .db , operation , "" , err )
83
68
}
84
69
if err := tx .Commit (); err != nil {
85
- return & types.InternalServiceError {
86
- Message : fmt .Sprintf ("%s operation failed. Failed to commit transaction. Error: %v" , operation , err ),
87
- }
70
+ return convertCommonErrors (m .db , operation , "Failed to commit transaction." , err )
88
71
}
89
72
return nil
90
73
}
@@ -126,3 +109,41 @@ func deserializePageToken(payload []byte) (int64, error) {
126
109
}
127
110
return int64 (binary .LittleEndian .Uint64 (payload )), nil
128
111
}
112
+
113
+ func convertCommonErrors (
114
+ errChecker sqlplugin.ErrorChecker ,
115
+ operation , message string ,
116
+ err error ,
117
+ ) error {
118
+ switch err .(type ) {
119
+ case * persistence.ConditionFailedError ,
120
+ * persistence.CurrentWorkflowConditionFailedError ,
121
+ * persistence.WorkflowExecutionAlreadyStartedError ,
122
+ * persistence.ShardOwnershipLostError ,
123
+ * persistence.TimeoutError ,
124
+ * types.DomainAlreadyExistsError ,
125
+ * types.EntityNotExistsError ,
126
+ * types.ServiceBusyError ,
127
+ * types.InternalServiceError :
128
+ return err
129
+ }
130
+ if errChecker .IsNotFoundError (err ) {
131
+ return & types.EntityNotExistsError {
132
+ Message : fmt .Sprintf ("%v failed. %s Error: %v " , operation , message , err ),
133
+ }
134
+ }
135
+
136
+ if errChecker .IsTimeoutError (err ) {
137
+ return & persistence.TimeoutError {Msg : fmt .Sprintf ("%v timed out. %s Error: %v" , operation , message , err )}
138
+ }
139
+
140
+ if errChecker .IsThrottlingError (err ) {
141
+ return & types.ServiceBusyError {
142
+ Message : fmt .Sprintf ("%v operation failed. %s Error: %v" , operation , message , err ),
143
+ }
144
+ }
145
+
146
+ return & types.InternalServiceError {
147
+ Message : fmt .Sprintf ("%v operation failed. %s Error: %v" , operation , message , err ),
148
+ }
149
+ }
0 commit comments