Skip to content

Commit 4f86a09

Browse files
committed
fix(midway-component-fetch): callback of exception
1 parent a1eb8dd commit 4f86a09

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/midway-component-fetch/src/lib/fetch.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,25 @@ export class FetchComponent {
111111
return ret
112112
}
113113
catch (ex) {
114-
if (typeof config.processEx === 'function') {
114+
if (config.enableDefaultCallbacks) {
115+
if (typeof defaultfetchConfigCallbacks.processEx === 'function') {
116+
return defaultfetchConfigCallbacks.processEx({
117+
id,
118+
ctx: this.ctx,
119+
opts,
120+
exception: ex as Error,
121+
})
122+
}
123+
}
124+
else if (typeof config.processEx === 'function') {
115125
return config.processEx({
116126
id,
117127
ctx: this.ctx,
118128
opts,
119129
exception: ex as Error,
120130
})
121131
}
122-
else {
123-
throw ex
124-
}
132+
throw ex
125133
}
126134
}
127135

packages/midway-component-fetch/src/lib/helper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const afterResponse: FetchComponentConfig['afterResponse'] = async (options) =>
114114
fetchRequestSpanMap.delete(id)
115115
}
116116

117-
export const handleEx: FetchComponentConfig['processEx'] = (options) => {
117+
export const processEx: FetchComponentConfig['processEx'] = (options) => {
118118
const { id, ctx, exception } = options
119119
const time = genISO8601String()
120120
const mem = humanMemoryUsage()
@@ -160,7 +160,7 @@ export const defaultfetchConfigCallbacks = {
160160
// genRequestHeaders,
161161
beforeRequest,
162162
afterResponse,
163-
handleEx,
163+
processEx,
164164
}
165165

166166
export function retrieveHeadersItem(

0 commit comments

Comments
 (0)