Skip to content

Commit 2f966ae

Browse files
committed
version: 1.8.7
1 parent 247d499 commit 2f966ae

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

packages/hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-hooks-plus",
3-
"version": "1.8.6",
3+
"version": "1.8.7",
44
"description": "Vue hooks library",
55
"files": [
66
"dist",

packages/use-request/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue-hooks-plus/use-request",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Vue use-request hooks library",
55
"files": [
66
"dist",

packages/use-request/src/Fetch.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
116116
)
117117
// Do you want to stop the request
118118
if (stopNow) {
119-
return new Promise(() => { })
119+
return new Promise(() => {})
120120
}
121121

122122
this.setState({
@@ -130,8 +130,22 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
130130
return Promise.resolve(state.data)
131131
}
132132

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+
}
135149

136150
try {
137151
// 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> {
140154
const requestReturnResponse = (res: any) => {
141155
// The request has been cancelled, and the count will be inconsistent with the currentCount
142156
if (currentCount !== this.count) {
143-
return new Promise(() => { })
157+
return new Promise(() => {})
144158
}
145159
// Format data
146160
const formattedResult = this.options.formatResult ? this.options.formatResult(res) : res
@@ -174,7 +188,7 @@ export default class Fetch<TData, TParams extends unknown[] = any> {
174188
return requestReturnResponse(servicePromiseResult)
175189
} catch (error) {
176190
if (currentCount !== this.count) {
177-
return new Promise(() => { })
191+
return new Promise(() => {})
178192
}
179193

180194
this.setState({

0 commit comments

Comments
 (0)