From c160884ae939cd2bb1a6d1c979ae0949c4eeab18 Mon Sep 17 00:00:00 2001 From: winwin2011 Date: Sun, 9 Jan 2022 00:48:38 +0800 Subject: [PATCH] feat: http-secure more log --- .../src/lib/http-secure/src/index.ts | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/hexon-web/src/lib/http-secure/src/index.ts b/packages/hexon-web/src/lib/http-secure/src/index.ts index e61f61ac..4a5092ac 100644 --- a/packages/hexon-web/src/lib/http-secure/src/index.ts +++ b/packages/hexon-web/src/lib/http-secure/src/index.ts @@ -1,20 +1,24 @@ import axios, { AxiosRequestConfig, AxiosResponse } from "axios" import CryptoJS from "crypto-js" import JSEncrypt from "jsencrypt" -import { HTMLAttributes } from "vue" interface IHttpSecureOption { onDisable?(): void } +interface IRawData { + url: string + data: any +} + export default function createHttpSecureAxios( config?: AxiosRequestConfig, option: IHttpSecureOption = {} ) { let id = 1 - const urlMap = new Map() - // TODO log response data if secure enabled + const rawMap = new Map() + const onDisable = option.onDisable ?? (() => {}) const instance = axios.create(config) @@ -47,7 +51,7 @@ export default function createHttpSecureAxios( //#region save url config.httpSecureId = id - urlMap.set(id, config.url || "") + rawMap.set(id, { url: config.url || "", data: config.data }) id++ //#endregion @@ -89,8 +93,11 @@ export default function createHttpSecureAxios( //#region restore url if (res.config.httpSecureId !== void 0) { - res.config.url = urlMap.get(res.config.httpSecureId) || "" - urlMap.delete(res.config.httpSecureId) + const { url = "", data = {} } = + rawMap.get(res.config.httpSecureId) || {} + res.config.url = url + res.config.data = data + rawMap.delete(res.config.httpSecureId) } //#endregion @@ -116,8 +123,11 @@ export default function createHttpSecureAxios( const res = err.response as AxiosResponse //#region restore url if (res.config.httpSecureId !== void 0) { - res.config.url = urlMap.get(res.config.httpSecureId) || "" - urlMap.delete(res.config.httpSecureId) + const { url = "", data = {} } = + rawMap.get(res.config.httpSecureId) || {} + res.config.url = url + res.config.data = data + rawMap.delete(res.config.httpSecureId) } //#endregion