@ibiz-template/core 0.0.1-alpha.5 → 0.0.1-alpha.6

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 请求状态码文本
3
+ */
4
+ export declare const HttpStatusMessageConst: Record<number, string>;
5
+ //# sourceMappingURL=http-status-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-status-message.d.ts","sourceRoot":"","sources":["../../../src/constant/http-status-message/http-status-message.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAgBzD,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 请求状态码文本
3
+ */
4
+ export const HttpStatusMessageConst = {
5
+ 200: '服务器成功返回请求的数据。',
6
+ 201: '新建或修改数据成功。',
7
+ 202: '一个请求已经进入后台排队(异步任务)。',
8
+ 204: '删除数据成功。',
9
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
10
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
11
+ 403: '用户得到授权,但是访问是被禁止的。',
12
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
13
+ 406: '请求的格式不可得。',
14
+ 410: '请求的资源被永久删除,且不会再得到的。',
15
+ 422: '当创建一个对象时,发生一个验证错误。',
16
+ 500: '服务器发生错误,请检查服务器。',
17
+ 502: '网关错误。',
18
+ 503: '服务不可用,服务器暂时过载或维护。',
19
+ 504: '网关超时。',
20
+ };
@@ -1,2 +1,3 @@
1
1
  export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC"}
@@ -1 +1,2 @@
1
1
  export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
@@ -1 +1 @@
1
- {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../src/error/http-error/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAElD;;;;;;;;GAQG;AACH,qBAAa,SAAU,YAAW,KAAK;IACrC,IAAI,EAAE,MAAM,CAAe;IAE3B,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,aAAa,CAAC;gBAEb,GAAG,EAAE,UAAU;CAe5B"}
1
+ {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../src/error/http-error/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD;;;;;;;;GAQG;AACH,qBAAa,SAAU,YAAW,KAAK;IACrC,IAAI,EAAE,MAAM,CAAe;IAE3B,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,aAAa,CAAC;gBAEb,GAAG,EAAE,UAAU;CAqB5B"}
@@ -1,3 +1,4 @@
1
+ import { HttpStatusMessageConst } from '../../constant';
1
2
  /**
2
3
  * 请求异常
3
4
  *
@@ -19,6 +20,12 @@ export class HttpError {
19
20
  else {
20
21
  this.message = res.statusText;
21
22
  }
23
+ if (!this.message) {
24
+ this.message = HttpStatusMessageConst[res.status];
25
+ }
26
+ if (!this.message) {
27
+ this.message = '网络异常,请稍后重试!';
28
+ }
22
29
  this.status = res.status;
23
30
  }
24
31
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/core",
3
- "version": "0.0.1-alpha.5",
3
+ "version": "0.0.1-alpha.6",
4
4
  "description": "核心包",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -28,10 +28,12 @@
28
28
  "devDependencies": {
29
29
  "@types/pluralize": "^0.0.29",
30
30
  "@types/qs": "^6.9.7",
31
+ "lodash-es": "^4.17.21",
31
32
  "qx-util": "^0.4.1"
32
33
  },
33
34
  "peerDependencies": {
35
+ "lodash-es": "^4.17.21",
34
36
  "qx-util": "^0.4.1"
35
37
  },
36
- "gitHead": "8c4920248d5047ef434647c7f3707b49cb4d7077"
38
+ "gitHead": "0af61790674d0f38ffcf2697fc8b2d2324507ce7"
37
39
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 请求状态码文本
3
+ */
4
+ export const HttpStatusMessageConst: Record<number, string> = {
5
+ 200: '服务器成功返回请求的数据。',
6
+ 201: '新建或修改数据成功。',
7
+ 202: '一个请求已经进入后台排队(异步任务)。',
8
+ 204: '删除数据成功。',
9
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
10
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
11
+ 403: '用户得到授权,但是访问是被禁止的。',
12
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
13
+ 406: '请求的格式不可得。',
14
+ 410: '请求的资源被永久删除,且不会再得到的。',
15
+ 422: '当创建一个对象时,发生一个验证错误。',
16
+ 500: '服务器发生错误,请检查服务器。',
17
+ 502: '网关错误。',
18
+ 503: '服务不可用,服务器暂时过载或维护。',
19
+ 504: '网关超时。',
20
+ };
@@ -1 +1,2 @@
1
1
  export { CoreConst } from './core/core';
2
+ export { HttpStatusMessageConst } from './http-status-message/http-status-message';
@@ -1,4 +1,5 @@
1
1
  import { AxiosError, AxiosResponse } from 'axios';
2
+ import { HttpStatusMessageConst } from '../../constant';
2
3
 
3
4
  /**
4
5
  * 请求异常
@@ -27,6 +28,12 @@ export class HttpError implements Error {
27
28
  } else {
28
29
  this.message = res.statusText;
29
30
  }
31
+ if (!this.message) {
32
+ this.message = HttpStatusMessageConst[res.status];
33
+ }
34
+ if (!this.message) {
35
+ this.message = '网络异常,请稍后重试!';
36
+ }
30
37
  this.status = res.status;
31
38
  } else {
32
39
  this.message = err.message;