@@ -116,7 +116,7 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
116
116
)
117
117
// Do you want to stop the request
118
118
if ( stopNow ) {
119
- return new Promise ( ( ) => { } )
119
+ return new Promise ( ( ) => { } )
120
120
}
121
121
122
122
this . setState ( {
@@ -130,8 +130,22 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
130
130
return Promise . resolve ( state . data )
131
131
}
132
132
133
- // Return before request
134
- this . options . onBefore ?.( params )
133
+ // The 'onBefore' configuration item error no longer interrupts the entire code flow
134
+ try {
135
+ // Return before request
136
+ this . options . onBefore ?.( params )
137
+ } catch ( error ) {
138
+ // The 'onBefore' configuration item error no longer interrupts the entire code flow
139
+ this . setState ( {
140
+ error,
141
+ loading : false ,
142
+ } )
143
+ this . options . onError ?.( error as Error , params )
144
+ this . runPluginHandler ( 'onError' , error , params )
145
+
146
+ // Manually intercept the error and return a Promise with an empty status
147
+ return new Promise ( ( ) => { } )
148
+ }
135
149
136
150
try {
137
151
// Start the request with the replace service, if it contains the onRequest event name
@@ -140,7 +154,7 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
140
154
const requestReturnResponse = ( res : any ) => {
141
155
// The request has been cancelled, and the count will be inconsistent with the currentCount
142
156
if ( currentCount !== this . count ) {
143
- return new Promise ( ( ) => { } )
157
+ return new Promise ( ( ) => { } )
144
158
}
145
159
// Format data
146
160
const formattedResult = this . options . formatResult ? this . options . formatResult ( res ) : res
@@ -174,7 +188,7 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
174
188
return requestReturnResponse ( servicePromiseResult )
175
189
} catch ( error ) {
176
190
if ( currentCount !== this . count ) {
177
- return new Promise ( ( ) => { } )
191
+ return new Promise ( ( ) => { } )
178
192
}
179
193
180
194
this . setState ( {
0 commit comments