@gm-mobile/mp-request 3.12.12-beta.0 → 3.12.12-beta.1
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/util.ts +29 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp-request",
|
|
3
|
-
"version": "3.12.12-beta.
|
|
3
|
+
"version": "3.12.12-beta.1",
|
|
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.12-beta.
|
|
24
|
-
"@gm-mobile/locales": "^3.12.12-beta.
|
|
25
|
-
"@gm-mobile/mp": "^3.12.12-beta.
|
|
23
|
+
"@gm-mobile/c-tool": "^3.12.12-beta.1",
|
|
24
|
+
"@gm-mobile/locales": "^3.12.12-beta.1",
|
|
25
|
+
"@gm-mobile/mp": "^3.12.12-beta.1",
|
|
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": "8241f847ca2e7cfbbb67076d8d89f00e20c3977b"
|
|
34
34
|
}
|
package/src/util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
1
|
+
import _, { isObject } from 'lodash'
|
|
2
2
|
|
|
3
3
|
import { parseUrl, stringifyUrl } from 'query-string'
|
|
4
4
|
import { getLocale } from '@gm-mobile/locales'
|
|
@@ -166,8 +166,12 @@ function getUrlRandom(url: string): string {
|
|
|
166
166
|
function formatErrorMessage(
|
|
167
167
|
message: string,
|
|
168
168
|
statusCodeMap: Record<string, string>,
|
|
169
|
-
response?: AxiosResponse
|
|
169
|
+
response?: AxiosResponse,
|
|
170
|
+
req?: AxiosRequestConfig
|
|
170
171
|
): string {
|
|
172
|
+
if (message === '网络连接异常,请检查网络设置') {
|
|
173
|
+
return message
|
|
174
|
+
}
|
|
171
175
|
const formatDate = (timestamp: number) => {
|
|
172
176
|
const date = new Date(timestamp)
|
|
173
177
|
const year = date.getFullYear()
|
|
@@ -180,30 +184,47 @@ function formatErrorMessage(
|
|
|
180
184
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
|
181
185
|
}
|
|
182
186
|
|
|
187
|
+
const result = (response?.headers?.['grpc-message'] || '').split('|')
|
|
188
|
+
const gRPCMessageDetail: string = atob(result.slice(1).join('|'))
|
|
189
|
+
|
|
183
190
|
const code = response?.data?.code || 0
|
|
184
191
|
let customizeReason = response?.data.message.detail?.reason
|
|
185
192
|
const codeMessage = statusCodeMap[code]
|
|
186
|
-
const rid =
|
|
193
|
+
const rid =
|
|
194
|
+
response?.config?.headers?.['X-Request-Id'] ||
|
|
195
|
+
req?.headers?.['X-Request-Id']
|
|
187
196
|
const timestamp =
|
|
188
|
-
response?.config
|
|
197
|
+
response?.config?.headers?.['X-Timestamp'] ||
|
|
198
|
+
req?.headers?.['X-Timestamp'] ||
|
|
199
|
+
new Date().valueOf()
|
|
189
200
|
const formatedDate = formatDate(Number(timestamp))
|
|
190
201
|
|
|
191
202
|
const isGrpcStatusCode = code < 2000
|
|
192
203
|
|
|
204
|
+
if (gRPCMessageDetail && isObject(gRPCMessageDetail)) {
|
|
205
|
+
try {
|
|
206
|
+
customizeReason = codeMessage
|
|
207
|
+
customizeReason += ` ${JSON.stringify(gRPCMessageDetail)}`
|
|
208
|
+
} catch {}
|
|
209
|
+
}
|
|
210
|
+
|
|
193
211
|
if (!customizeReason) {
|
|
194
|
-
customizeReason =
|
|
212
|
+
customizeReason =
|
|
213
|
+
gRPCMessageDetail || codeMessage || message || getLocale('服务异常')
|
|
195
214
|
}
|
|
196
215
|
|
|
197
216
|
let reason = `${code} ${customizeReason}`
|
|
198
217
|
|
|
199
218
|
// 服务异常没有 rid
|
|
200
|
-
if (isGrpcStatusCode
|
|
201
|
-
|
|
219
|
+
if (isGrpcStatusCode) {
|
|
220
|
+
if (rid) {
|
|
221
|
+
reason += ` rid: ${rid}`
|
|
222
|
+
}
|
|
223
|
+
reason += ` 日期: ${formatedDate}`
|
|
202
224
|
}
|
|
203
225
|
|
|
204
226
|
return reason
|
|
205
227
|
}
|
|
206
|
-
|
|
207
228
|
export {
|
|
208
229
|
requestUrl,
|
|
209
230
|
requestEnvUrl,
|