Skip to content

Commit

Permalink
feat: http-secure more log
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJianghao committed Jan 8, 2022
1 parent 3a7270c commit c160884
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/hexon-web/src/lib/http-secure/src/index.ts
Original file line number Diff line number Diff line change
@@ -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<number, string>()

// TODO log response data if secure enabled
const rawMap = new Map<number, IRawData>()

const onDisable = option.onDisable ?? (() => {})
const instance = axios.create(config)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit c160884

Please sign in to comment.