@gm-mobile/mp-request 3.12.4 → 3.12.5-beta.0
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.
- package/package.json +5 -5
- package/src/config_error.ts +1 -1
- package/src/index.ts +2 -0
- package/src/util.ts +37 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp-request",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.5-beta.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "zhongsink <zhongink@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@gm-mobile/c-tool": "^3.12.
|
|
24
|
-
"@gm-mobile/locales": "^3.12.
|
|
25
|
-
"@gm-mobile/mp": "^3.12.
|
|
23
|
+
"@gm-mobile/c-tool": "^3.12.5-beta.0",
|
|
24
|
+
"@gm-mobile/locales": "^3.12.5-beta.0",
|
|
25
|
+
"@gm-mobile/mp": "^3.12.5-beta.0",
|
|
26
26
|
"js-base64": "^3.6.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"taro-axios": "^1.1.1",
|
|
31
31
|
"weapp-cookie": "^1.4.6"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "b4c4723f59e2c855d0e19632f87c8d9a8a7a2088"
|
|
34
34
|
}
|
package/src/config_error.ts
CHANGED
package/src/index.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -154,6 +154,42 @@ function getUrlRandom(url: string): string {
|
|
|
154
154
|
return stringifyUrl(obj)
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* 格式化错误信息
|
|
159
|
+
*
|
|
160
|
+
* 异常编码不存在或<2000:
|
|
161
|
+
* <异常编码> <异常详细信息或异常编码翻译> rid: <请求ID> 日期: <请求时间>
|
|
162
|
+
*
|
|
163
|
+
* 异常编码>=2000:
|
|
164
|
+
* <异常编码> <异常详细信息或异常编码翻译>
|
|
165
|
+
*/
|
|
166
|
+
function formatErrorMessage(
|
|
167
|
+
code: number,
|
|
168
|
+
message: string,
|
|
169
|
+
statusCodeMap: Record<string, string>,
|
|
170
|
+
response?: AxiosResponse
|
|
171
|
+
): string {
|
|
172
|
+
let customizeReason = response?.data.message.detail?.reason
|
|
173
|
+
const codeMessage = statusCodeMap[code]
|
|
174
|
+
const rid = response?.config.headers['X-Request-Id']
|
|
175
|
+
const timestamp =
|
|
176
|
+
response?.config.headers['X-Timestamp'] || new Date().valueOf()
|
|
177
|
+
|
|
178
|
+
const isGrpcStatusCode = code < 2000
|
|
179
|
+
|
|
180
|
+
if (!customizeReason) {
|
|
181
|
+
customizeReason = codeMessage || message || '服务异常'
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let reason = `${code} ${customizeReason}`
|
|
185
|
+
|
|
186
|
+
if (isGrpcStatusCode) {
|
|
187
|
+
reason += ` rid: ${rid} 日期: ${timestamp}`
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return reason
|
|
191
|
+
}
|
|
192
|
+
|
|
157
193
|
export {
|
|
158
194
|
requestUrl,
|
|
159
195
|
requestEnvUrl,
|
|
@@ -165,4 +201,5 @@ export {
|
|
|
165
201
|
isProduction,
|
|
166
202
|
requestTrim,
|
|
167
203
|
formatToResponse,
|
|
204
|
+
formatErrorMessage,
|
|
168
205
|
}
|