feat(request): add a response-interceptor seam

Add `extraResponseInterceptors` next to the existing request-interceptor
seam and wire it into the request config, so build-time tooling can react
to responses (e.g. clear a one-shot request-scoped hint after a write
completes). Default is an empty list — no behavior change by default.
This commit is contained in:
gitlawr
2026-06-03 10:14:50 +08:00
committed by jialin
parent 9061fa08ba
commit d2d82ee5ee
2 changed files with 16 additions and 2 deletions
+8 -2
View File
@@ -4,7 +4,10 @@ import { history, RequestConfig } from '@umijs/max';
import { message } from 'antd';
import { DEFAULT_ENTER_PAGE } from './config/settings';
import ErrorMessageContent from './pages/_components/error-message-content';
import { extraRequestInterceptors } from './request.extensions';
import {
extraRequestInterceptors,
extraResponseInterceptors
} from './request.extensions';
// these APIs do not via the GPUSTACK_API_BASE_URL
const NoBaseURLAPIs = ['/auth', '/v1', '/version', '/proxy', '/update'];
@@ -49,6 +52,9 @@ export const requestConfig: RequestConfig = {
(response) => {
// to do something
return response;
}
},
// Build-time tooling can plug additional response interceptors via
// `request.extensions.ts`. Default is an empty list.
...extraResponseInterceptors
]
};
+8
View File
@@ -13,3 +13,11 @@ export type RequestInterceptor = (
) => { url: string; options: Record<string, any> };
export const extraRequestInterceptors: RequestInterceptor[] = [];
// Response-side counterpart. Each interceptor receives the (successful)
// response and returns it; tooling may overwrite this file to react to
// responses (e.g. clearing a one-shot request-scoped hint after a write
// completes). Default is an empty list.
export type ResponseInterceptor = (response: any) => any;
export const extraResponseInterceptors: ResponseInterceptor[] = [];