@gm-mobile/mp-request 3.12.5-beta.1 → 3.12.5

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/util.ts +16 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/mp-request",
3
- "version": "3.12.5-beta.1",
3
+ "version": "3.12.5",
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.5-beta.1",
24
- "@gm-mobile/locales": "^3.12.5-beta.1",
25
- "@gm-mobile/mp": "^3.12.5-beta.1",
23
+ "@gm-mobile/c-tool": "^3.12.5",
24
+ "@gm-mobile/locales": "^3.12.5",
25
+ "@gm-mobile/mp": "^3.12.5",
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": "505111789ec1ae21ea8d27454791a6cb9ea776b1"
33
+ "gitHead": "817c9bedcdffcdbd1878387a2dd946adeccc5c07"
34
34
  }
package/src/util.ts CHANGED
@@ -168,12 +168,25 @@ function formatErrorMessage(
168
168
  statusCodeMap: Record<string, string>,
169
169
  response?: AxiosResponse
170
170
  ): string {
171
+ const formatDate = (timestamp: number) => {
172
+ const date = new Date(timestamp)
173
+ const year = date.getFullYear()
174
+ const month = String(date.getMonth() + 1).padStart(2, '0')
175
+ const day = String(date.getDate()).padStart(2, '0')
176
+ const hours = String(date.getHours()).padStart(2, '0')
177
+ const minutes = String(date.getMinutes()).padStart(2, '0')
178
+ const seconds = String(date.getSeconds()).padStart(2, '0')
179
+
180
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
181
+ }
182
+
171
183
  const code = response?.data?.code || 0
172
184
  let customizeReason = response?.data.message.detail?.reason
173
185
  const codeMessage = statusCodeMap[code]
174
186
  const rid = response?.config.headers['X-Request-Id']
175
187
  const timestamp =
176
188
  response?.config.headers['X-Timestamp'] || new Date().valueOf()
189
+ const formatedDate = formatDate(Number(timestamp))
177
190
 
178
191
  const isGrpcStatusCode = code < 2000
179
192
 
@@ -183,8 +196,9 @@ function formatErrorMessage(
183
196
 
184
197
  let reason = `${code} ${customizeReason}`
185
198
 
186
- if (isGrpcStatusCode) {
187
- reason += ` rid: ${rid} 日期: ${timestamp}`
199
+ // 服务异常没有 rid
200
+ if (isGrpcStatusCode && customizeReason !== '服务异常') {
201
+ reason += ` rid: ${rid} 日期: ${formatedDate}`
188
202
  }
189
203
 
190
204
  return reason