abler-api 0.1.48 → 0.1.50

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/dist/cjs/pp-util.js +21 -11
  2. package/package.json +1 -1
@@ -1423,26 +1423,36 @@ class apiUtil$2 {
1423
1423
  const authorization = getBasicAuthorization(req);
1424
1424
 
1425
1425
  if (!authorization) {
1426
- res.set('WWW-Authenticate', 'Basic realm=need username and password');
1427
- return res.sendStatus(401);
1426
+ throw {
1427
+ status: 401,
1428
+ error: {
1429
+ success: false,
1430
+ stateCode: 40101,
1431
+ message: 'need username and password'
1432
+ }
1433
+ };
1428
1434
  }
1429
1435
 
1430
1436
  if (!(await apiUtil$2._validateBasicAuth(authorization.name, authorization.pass))) {
1431
- res.set('WWW-Authenticate', 'Basic realm=invalid username or password');
1432
- return res.sendStatus(401);
1437
+ throw {
1438
+ status: 401,
1439
+ error: {
1440
+ success: false,
1441
+ stateCode: 40102,
1442
+ message: 'invalid username or password'
1443
+ }
1444
+ };
1433
1445
  }
1434
1446
  } catch (e) {
1435
1447
  if (e.status === 401) {
1436
- try {
1448
+ if (e.message) try {
1437
1449
  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
- }
1450
+ return res.status(401).send(e.message);
1451
+ } catch {}
1452
+ res.set('WWW-Authenticate', `Basic realm=validate fail`);
1443
1453
  }
1444
1454
 
1445
- return res.status(e.status || 500).send(e);
1455
+ return res.status(e.status || 500).send(e.error || e);
1446
1456
  }
1447
1457
 
1448
1458
  return next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abler-api",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "description": "API服务相关工具",
5
5
  "main": "./dist/cjs/pp-util.js",
6
6
  "-module": "./dist/es/pp-util.js",