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.
- package/dist/cjs/pp-util.js +18 -10
- package/package.json +1 -1
package/dist/cjs/pp-util.js
CHANGED
|
@@ -1423,23 +1423,31 @@ class apiUtil$2 {
|
|
|
1423
1423
|
const authorization = getBasicAuthorization(req);
|
|
1424
1424
|
|
|
1425
1425
|
if (!authorization) {
|
|
1426
|
-
|
|
1427
|
-
|
|
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
|
-
|
|
1432
|
-
|
|
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.
|
|
1439
|
-
} catch {
|
|
1440
|
-
|
|
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);
|