abler-api 0.1.48 → 0.1.49

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 +18 -10
  2. package/package.json +1 -1
@@ -1423,23 +1423,31 @@ 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
+ code: 40101,
1430
+ message: 'need username and password'
1431
+ }
1432
+ };
1428
1433
  }
1429
1434
 
1430
1435
  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);
1436
+ throw {
1437
+ status: 401,
1438
+ error: {
1439
+ code: 40102,
1440
+ message: 'invalid username or password'
1441
+ }
1442
+ };
1433
1443
  }
1434
1444
  } catch (e) {
1435
1445
  if (e.status === 401) {
1436
- try {
1446
+ if (e.message) try {
1437
1447
  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
- }
1448
+ return res.status(401).send(e.message);
1449
+ } catch {}
1450
+ res.set('WWW-Authenticate', `Basic realm=validate fail`);
1443
1451
  }
1444
1452
 
1445
1453
  return res.status(e.status || 500).send(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abler-api",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "API服务相关工具",
5
5
  "main": "./dist/cjs/pp-util.js",
6
6
  "-module": "./dist/es/pp-util.js",