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