Skip to content

Commit

Permalink
Merge pull request #119 from gmfe/feature/2411_erp
Browse files Browse the repository at this point in the history
Feature/2411 erp
  • Loading branch information
Yiiu authored Dec 9, 2024
2 parents 3329e1c + 2345f6e commit 088a441
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 35 deletions.
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry: https://registry.npmmirror.com/
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"graphType": "all"
}
},
"version": "2.14.9"
}
"version": "2.14.11"
}
4 changes: 2 additions & 2 deletions packages/analyse/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/analyse",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/fingerprint": "^2.14.9",
"@gm-common/fingerprint": "^2.14.11",
"axios": "^0.21.0",
"query-string": "^6.13.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/date/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/date",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/fingerprint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/fingerprint",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/tool": "^2.14.9",
"@gm-common/tool": "^2.14.11",
"@types/fingerprintjs2": "^2.0.0",
"fingerprintjs2": "^2.1.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/google-map/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/google-map",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/graph",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/hooks",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/tool": "^2.14.9",
"@gm-common/tool": "^2.14.11",
"ts-config-gm-react-app": "^3.4.5"
},
"gitHead": "9f7689a5dd20cd025f78e30a0aec65cf19aed3dc"
Expand Down
6 changes: 3 additions & 3 deletions packages/image/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/image",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "zhongsink <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,11 +21,11 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/qiniup": "^2.14.9",
"@gm-common/qiniup": "^2.14.11",
"lodash": "^4.17.20"
},
"devDependencies": {
"@gm-common/x-request": "^2.14.9"
"@gm-common/x-request": "^2.14.11"
},
"gitHead": "9f7689a5dd20cd025f78e30a0aec65cf19aed3dc"
}
2 changes: 1 addition & 1 deletion packages/locales/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/locales",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/map/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/map",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/mobx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/mobx",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/tool": "^2.14.9",
"@gm-common/tool": "^2.14.11",
"lodash": "^4.17.20",
"mobx": "^6.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/number/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/number",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/qiniup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/qiniup",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "zhongsink <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/tool": "^2.14.9",
"@gm-common/tool": "^2.14.11",
"axios": "^0.21.0",
"lodash": "^4.17.19"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/request/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/request",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,10 +21,10 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/analyse": "^2.14.9",
"@gm-common/fingerprint": "^2.14.9",
"@gm-common/locales": "^2.14.9",
"@gm-common/tool": "^2.14.9",
"@gm-common/analyse": "^2.14.11",
"@gm-common/fingerprint": "^2.14.11",
"@gm-common/locales": "^2.14.11",
"@gm-common/tool": "^2.14.11",
"axios": "^0.21.0",
"lodash": "^4.17.20"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/router",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/tool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/tool",
"version": "2.14.9",
"version": "2.14.11",
"description": "",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/wx-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/wx-sdk",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "liyatang <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand Down
10 changes: 5 additions & 5 deletions packages/x-request/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gm-common/x-request",
"version": "2.14.9",
"version": "2.14.11",
"description": "> TODO: description",
"author": "zhongsink <[email protected]>",
"homepage": "https://github.com/gmfe/gm-common#readme",
Expand All @@ -21,10 +21,10 @@
"url": "https://github.com/gmfe/gm-common/issues"
},
"dependencies": {
"@gm-common/analyse": "^2.14.9",
"@gm-common/fingerprint": "^2.14.9",
"@gm-common/locales": "^2.14.9",
"@gm-common/tool": "^2.14.9",
"@gm-common/analyse": "^2.14.11",
"@gm-common/fingerprint": "^2.14.11",
"@gm-common/locales": "^2.14.11",
"@gm-common/tool": "^2.14.11",
"axios": "^0.21.0",
"js-base64": "^3.6.0",
"lodash": "^4.17.19"
Expand Down
2 changes: 1 addition & 1 deletion packages/x-request/src/config_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function wrap(
// 如果错误了
if (_.isNaN(code) || !sucCode.includes(code + '')) {
if (code) {
message = `${getLocale('未知错误')}: ${code}`
message = `${getLocale('未知错误')}`
}

errorCallback(message, wrapRes)
Expand Down
1 change: 1 addition & 0 deletions packages/x-request/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export {
clearAuth,
setAccessToken,
}
export { formatErrorMessage } from './util'
export type { Response } from './types'
52 changes: 52 additions & 0 deletions packages/x-request/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function parseResponseHeaders(response: AxiosResponse) {
gRPCStatus: isNaN ? -1 : gRPCStatus,
}
}

function formatToResponse<T>(response: AxiosResponse<T>) {
const { gRPCMessageDetail, gRPCMessage, gRPCStatus } = parseResponseHeaders(
response,
Expand Down Expand Up @@ -94,6 +95,56 @@ function requestTrim(obj: { [key: string]: any }) {
return tailRequestTrim(obj, {})
}

/**
* 格式化错误信息
*
* 异常编码不存在或<2000:
* <异常编码> <异常详细信息或异常编码翻译> rid: <请求ID> 日期: <请求时间>
*
* 异常编码>=2000:
* <异常编码> <异常详细信息或异常编码翻译>
*/
function formatErrorMessage(
message: string,
statusCodeMap: Record<string, string>,
response?: AxiosResponse,
): string {
const formatDate = (timestamp: number) => {
const date = new Date(timestamp)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0')

return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}

const code = response?.data?.code || 0
let customizeReason = response?.data.message.detail?.reason
const codeMessage = statusCodeMap[code]
const rid = response?.config.headers['X-Request-Id']
const timestamp =
response?.config.headers['X-Timestamp'] || new Date().valueOf()
const formatedDate = formatDate(Number(timestamp))

const isGrpcStatusCode = code < 2000

if (!customizeReason) {
customizeReason = codeMessage || message || '服务异常'
}

let reason = `${code} ${customizeReason}`

// 服务异常没有 rid
if (isGrpcStatusCode && customizeReason !== '服务异常') {
reason += ` rid: ${rid} 日期: ${formatedDate}`
}

return reason
}

export {
formatToResponse,
accessTokenKey,
Expand All @@ -105,4 +156,5 @@ export {
getErrorMessage,
atob,
requestTrim,
formatErrorMessage,
}

0 comments on commit 088a441

Please sign in to comment.