@clownlee/http 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { AxiosRequestConfig, AxiosResponse, CancelToken, CancelTokenSource, InternalAxiosRequestConfig } from 'axios';
1
+ import { AxiosRequestConfig, CancelToken, CancelTokenSource, InternalAxiosRequestConfig } from 'axios';
2
2
  import { Store } from 'pinia';
3
3
 
4
4
  /**
@@ -53,12 +53,14 @@ export interface HttpRequestConfig extends Omit<AxiosRequestConfig, 'cancelToken
53
53
  /**
54
54
  * HTTP 响应数据模型
55
55
  */
56
- export interface HttpResponse<T = any> extends Omit<AxiosResponse<T>, 'config'> {
57
- data: T;
58
- status: number;
59
- statusText: string;
60
- headers: Record<string, string>;
61
- config: HttpRequestConfig;
56
+ export interface HttpResponse<T = any> {
57
+ code: number;
58
+ message: string;
59
+ failure?: boolean;
60
+ success?: boolean;
61
+ data?: T;
62
+ timestamp?: string;
63
+ traceId?: string;
62
64
  }
63
65
  /**
64
66
  * HTTP 实例接口
@@ -1,11 +1,11 @@
1
1
  import { AxiosError, AxiosResponse } from 'axios';
2
- import { RefreshConfig } from '../types/request.types';
2
+ import { HttpResponse, RefreshConfig } from '../types/request.types';
3
3
  import { Store } from 'pinia';
4
4
 
5
5
  /**
6
6
  * 处理响应拦截器(成功响应)
7
7
  */
8
- export declare function handleResponseInterceptor<T = any>(response: AxiosResponse<T>, store: Store, refreshConfig: RefreshConfig): Promise<AxiosResponse<T>>;
8
+ export declare function handleResponseInterceptor<T = any>(response: AxiosResponse<HttpResponse<T>>, store: Store, refreshConfig: RefreshConfig): Promise<AxiosResponse<HttpResponse<T>>>;
9
9
  /**
10
10
  * 处理响应错误拦截器
11
11
  */
package/dist/index.js CHANGED
@@ -172,6 +172,17 @@ async function handleResponseInterceptor(response, store, refreshConfig) {
172
172
  throw new Error(responseData == null ? void 0 : responseData.message);
173
173
  } else if (code === 2001) {
174
174
  const config = response.config;
175
+ if (config._retry) {
176
+ window.parent.postMessage({
177
+ type: "error",
178
+ data: JSON.stringify({
179
+ code: responseData == null ? void 0 : responseData.code,
180
+ message: responseData == null ? void 0 : responseData.message,
181
+ action: "toLogin"
182
+ })
183
+ }, "*");
184
+ throw new Error(responseData == null ? void 0 : responseData.message);
185
+ }
175
186
  if (!refreshConfig || !store) {
176
187
  return response;
177
188
  }
@@ -199,7 +210,7 @@ async function handleResponseInterceptor(response, store, refreshConfig) {
199
210
  } else if (code > 0) {
200
211
  throw new Error(responseData == null ? void 0 : responseData.message);
201
212
  }
202
- return responseData;
213
+ return response;
203
214
  }
204
215
  async function handleResponseError(error) {
205
216
  throw error;
@@ -289,7 +300,7 @@ class RequestServiceClass {
289
300
  cancelToken: config.cancelToken && "token" in config.cancelToken ? config.cancelToken.token : config.cancelToken
290
301
  };
291
302
  const response = await instance.request(axiosConfig);
292
- return response;
303
+ return response.data;
293
304
  }
294
305
  /**
295
306
  * GET 请求
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clownlee/http",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "公共 HTTP 请求库,提供统一的 HTTP 请求能力和自动 token 刷新功能",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,6 +17,7 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "vite build",
20
+ "build:test": "vite build",
20
21
  "dev": "vite build --watch",
21
22
  "type-check": "vue-tsc --noEmit"
22
23
  },