refactor(request): unify response transformation methods and deprecate transformBackendResponse

This commit is contained in:
Soybean
2025-07-19 12:04:00 +08:00
parent 936b834e62
commit f83eefbc3e
4 changed files with 20 additions and 5 deletions

View File

@ -10,13 +10,21 @@ export function createDefaultOptions<
State extends Record<string, unknown> = Record<string, unknown>
>(options?: Partial<RequestOption<ResponseData, ApiData, State>>) {
const opts: RequestOption<ResponseData, ApiData, State> = {
defaultState: {} as State,
transform: async response => response.data as unknown as ApiData,
transformBackendResponse: async response => response.data as unknown as ApiData,
onRequest: async config => config,
isBackendSuccess: _response => true,
onBackendFail: async () => {},
transformBackendResponse: async response => response.data as unknown as ApiData,
onError: async () => {}
};
if (options?.transform) {
opts.transform = options.transform;
} else {
opts.transform = options?.transformBackendResponse || opts.transform;
}
Object.assign(opts, options);
return opts;