abler-api 0.1.46 → 0.1.48

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.
@@ -50,7 +50,10 @@ class apiUtil$2 {
50
50
  static testFlag = ppUtil$4.newGuid();
51
51
  static envId_dev = "?";
52
52
  static _validateBasicAuth = function (userName, password) {
53
- throw new Error('未设置基本验证函数');
53
+ throw {
54
+ status: 500,
55
+ message: 'no basic auth validator'
56
+ };
54
57
  }; // static apiCallRecSaver;
55
58
 
56
59
  static config(appConfig, appErrCfg, appDbSql) {
@@ -1424,13 +1427,22 @@ class apiUtil$2 {
1424
1427
  return res.sendStatus(401);
1425
1428
  }
1426
1429
 
1427
- if (!apiUtil$2._validateBasicAuth(authorization.name, authorization.pass)) {
1430
+ if (!(await apiUtil$2._validateBasicAuth(authorization.name, authorization.pass))) {
1428
1431
  res.set('WWW-Authenticate', 'Basic realm=invalid username or password');
1429
1432
  return res.sendStatus(401);
1430
1433
  }
1431
1434
  } catch (e) {
1432
- res.set('WWW-Authenticate', `Basic realm=${e.message}`);
1433
- return res.sendStatus(401);
1435
+ if (e.status === 401) {
1436
+ try {
1437
+ res.set('WWW-Authenticate', `Basic realm=${e.message}`);
1438
+ return res.sendStatus(401);
1439
+ } catch {
1440
+ res.set('WWW-Authenticate', 'Basic realm=validate fail');
1441
+ return res.status(401).send(e);
1442
+ }
1443
+ }
1444
+
1445
+ return res.status(e.status || 500).send(e);
1434
1446
  }
1435
1447
 
1436
1448
  return next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abler-api",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "description": "API服务相关工具",
5
5
  "main": "./dist/cjs/pp-util.js",
6
6
  "-module": "./dist/es/pp-util.js",