Skip to content

fix: the refresh token api request client #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web-antd/src/api/core/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { baseRequestClient, requestClient } from '#/api/request';
import { miniRequestClient, requestClient } from '#/api/request';

export interface CaptchaResult {
image: string;
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function loginApi(data: LoginParams) {
* 刷新accessToken
*/
export async function refreshTokenApi() {
return baseRequestClient.post<RefreshTokenResult>(
return miniRequestClient.post<RefreshTokenResult>(
'/api/v1/auth/tokens',
undefined,
{
Expand Down
35 changes: 35 additions & 0 deletions apps/web-antd/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,43 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) {
return client;
}

function createMiniRequestClient(
baseURL: string,
options?: RequestClientOptions,
) {
const client = new RequestClient({
...options,
baseURL,
});

// 处理返回的响应数据格式
client.addResponseInterceptor(
defaultResponseInterceptor({
codeField: 'code',
dataField: 'data',
successCode: 200,
}),
);

// 通用的错误处理
client.addResponseInterceptor(
errorMessageResponseInterceptor((msg: string, error) => {
const responseData = error?.response?.data ?? {};
const errorMessage =
responseData?.error ?? responseData?.msg ?? error?.msg ?? '';
message.error(errorMessage || msg);
}),
);

return client;
}

export const requestClient = createRequestClient(apiURL, {
responseReturn: 'data',
});

export const miniRequestClient = createMiniRequestClient(apiURL, {
responseReturn: 'data',
});

export const baseRequestClient = new RequestClient({ baseURL: apiURL });
8 changes: 6 additions & 2 deletions apps/web-antd/src/views/_core/authentication/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ const showNotification = () => {
),
]),
h('li', null, [
'计划于第二季度结束前完成',
h('span', { class: 'text-gray-500 ml-1' }, '(可能延期)'),
'作者已在拼命肝',
h(
'span',
{ class: 'text-gray-500 ml-1' },
'(为此带来的不便请谅解)',
),
]),
]),
]),
Expand Down