@@ -89,75 +89,62 @@ class ErrorCollector {
89
89
}
90
90
91
91
/**
92
- * Helper method for processing errors that are created with .noticeError()
92
+ * Gets the iterable property from the transaction based on the error type
93
93
*
94
94
* @param {Transaction } transaction the collected exception's transaction
95
- * @param {number } collectedErrors the number of errors we've successfully .collect()-ed
96
- * @param {number } expectedErrors the number of errors marked as expected in noticeError
97
- * @returns {Array.<number> } the updated [collectedErrors, expectedErrors] numbers post-processing
95
+ * @param {string } errorType the type of error: "user", "transactionException", "transaction"
96
+ * @returns {object[] } the iterable property from the transaction based on the error type
98
97
*/
99
- _processUserErrors ( transaction , collectedErrors , expectedErrors ) {
100
- if ( transaction . userErrors . length ) {
101
- for ( let i = 0 ; i < transaction . userErrors . length ; i ++ ) {
102
- const exception = transaction . userErrors [ i ]
103
- if ( this . collect ( transaction , exception ) ) {
104
- ++ collectedErrors
105
- // if we could collect it, then check if expected
106
- if (
107
- urltils . isExpectedError ( this . config , transaction . statusCode ) ||
108
- errorHelper . isExpectedException ( transaction , exception , this . config , urltils )
109
- ) {
110
- ++ expectedErrors
111
- }
112
- }
113
- }
98
+ _getIterableProperty ( transaction , errorType ) {
99
+ let iterableProperty = null
100
+ if ( errorType === 'user' ) {
101
+ iterableProperty = transaction . userErrors
114
102
}
115
-
116
- return [ collectedErrors , expectedErrors ]
103
+ if ( errorType === 'transactionException' ) {
104
+ iterableProperty = transaction . exceptions
105
+ }
106
+ return iterableProperty
117
107
}
118
108
119
109
/**
120
- * Helper method for processing exceptions on the transaction (transaction.exceptions array)
110
+ * Helper method for processing errors that are created with .noticeError(), exceptions
111
+ * on the transaction (transaction.exceptions array), and inferred errors based on Transaction metadata.
121
112
*
122
- * @param {Transaction } transaction the transaction being processed
123
- * @param {number } collectedErrors the number of errors successfully .collect()-ed
124
- * @param {number } expectedErrors the number of collected errors that were expected
125
- * @returns {Array.<number> } the updated [collectedErrors, expectedErrors] numbers post-processing
113
+ * @param {Transaction } transaction the collected exception's transaction
114
+ * @param {number } collectedErrors the number of errors we've successfully .collect()-ed
115
+ * @param {number } expectedErrors the number of errors marked as expected in noticeError
116
+ * @param {string } errorType the type of error to be processed; "user", "transactionException", "transaction"
117
+ * @returns {Array.<number> } the updated [collectedErrors, expectedErrors] numbers post processing
126
118
*/
127
- _processTransactionExceptions ( transaction , collectedErrors , expectedErrors ) {
128
- for ( let i = 0 ; i < transaction . exceptions . length ; i ++ ) {
129
- const exception = transaction . exceptions [ i ]
130
- if ( this . collect ( transaction , exception ) ) {
131
- ++ collectedErrors
132
- // if we could collect it, then check if expected
133
- if (
134
- urltils . isExpectedError ( this . config , transaction . statusCode ) ||
135
- errorHelper . isExpectedException ( transaction , exception , this . config , urltils )
136
- ) {
137
- ++ expectedErrors
119
+ _processErrors ( transaction , collectedErrors , expectedErrors , errorType ) {
120
+ const iterableProperty = this . _getIterableProperty ( transaction , errorType )
121
+ if ( iterableProperty === null && errorType === 'transaction' ) {
122
+ if ( this . collect ( transaction ) ) {
123
+ collectedErrors ++
124
+ if ( urltils . isExpectedError ( this . config , transaction . statusCode ) ) {
125
+ expectedErrors ++
138
126
}
139
127
}
128
+ return [ collectedErrors , expectedErrors ]
140
129
}
141
130
142
- return [ collectedErrors , expectedErrors ]
143
- }
131
+ if ( iterableProperty === null ) {
132
+ return [ collectedErrors , expectedErrors ]
133
+ }
144
134
145
- /**
146
- * Helper method for processing an inferred error based on Transaction metadata
147
- *
148
- * @param {Transaction } transaction the transaction being processed
149
- * @param {number } collectedErrors the number of errors successfully .collect()-ed
150
- * @param {number } expectedErrors the number of collected errors that were expected
151
- * @returns {Array.<number> } the updated [collectedErrors, expectedErrors] numbers post-processing
152
- */
153
- _processTransactionErrors ( transaction , collectedErrors , expectedErrors ) {
154
- if ( this . collect ( transaction ) ) {
155
- ++ collectedErrors
156
- if ( urltils . isExpectedError ( this . config , transaction . statusCode ) ) {
157
- ++ expectedErrors
135
+ for ( let i = 0 ; i < iterableProperty . length ; i ++ ) {
136
+ const exception = iterableProperty [ i ]
137
+ if ( ! this . collect ( transaction , exception ) ) {
138
+ continue
139
+ }
140
+ collectedErrors ++
141
+ if (
142
+ urltils . isExpectedError ( this . config , transaction . statusCode ) ||
143
+ errorHelper . isExpectedException ( transaction , exception , this . config , urltils )
144
+ ) {
145
+ expectedErrors ++
158
146
}
159
147
}
160
-
161
148
return [ collectedErrors , expectedErrors ]
162
149
}
163
150
@@ -183,27 +170,30 @@ class ErrorCollector {
183
170
184
171
// errors from noticeError are currently exempt from
185
172
// ignore and exclude rules
186
- ; [ collectedErrors , expectedErrors ] = this . _processUserErrors (
173
+ ; [ collectedErrors , expectedErrors ] = this . _processErrors (
187
174
transaction ,
188
175
collectedErrors ,
189
- expectedErrors
176
+ expectedErrors ,
177
+ 'user'
190
178
)
191
179
192
180
const isErroredTransaction = urltils . isError ( this . config , transaction . statusCode )
193
181
const isIgnoredErrorStatusCode = urltils . isIgnoredError ( this . config , transaction . statusCode )
194
182
195
183
// collect other exceptions only if status code is not ignored
196
184
if ( transaction . exceptions . length && ! isIgnoredErrorStatusCode ) {
197
- ; [ collectedErrors , expectedErrors ] = this . _processTransactionExceptions (
185
+ ; [ collectedErrors , expectedErrors ] = this . _processErrors (
198
186
transaction ,
199
187
collectedErrors ,
200
- expectedErrors
188
+ expectedErrors ,
189
+ 'transactionException'
201
190
)
202
191
} else if ( isErroredTransaction ) {
203
- ; [ collectedErrors , expectedErrors ] = this . _processTransactionErrors (
192
+ ; [ collectedErrors , expectedErrors ] = this . _processErrors (
204
193
transaction ,
205
194
collectedErrors ,
206
- expectedErrors
195
+ expectedErrors ,
196
+ 'transaction'
207
197
)
208
198
}
209
199
0 commit comments