soajs.controller 4.3.12 → 4.3.13
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/mw/keyACL/index.js +1 -1
- package/mw/mt/index.js +10 -5
- package/package.json +1 -1
- package/test/unit/utilities/utils.js +13 -0
- package/utilities/utils.js +3 -1
package/mw/keyACL/index.js
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = () => {
|
|
|
48
48
|
if (obj.service_v) {
|
|
49
49
|
let san_v = coreLibs.version.sanitize(obj.service_v);
|
|
50
50
|
if (!aclObj[san_v]) {
|
|
51
|
-
|
|
51
|
+
//NOTE: the error context already reports the service and the version
|
|
52
52
|
return cb(154, null);
|
|
53
53
|
}
|
|
54
54
|
aclObj = aclObj[san_v];
|
package/mw/mt/index.js
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = (configuration) => {
|
|
|
48
48
|
serviceInfo = req.soajs.controller.serviceParams.registry.versions[req.soajs.controller.serviceParams.version];
|
|
49
49
|
}
|
|
50
50
|
if (!serviceInfo) {
|
|
51
|
-
|
|
51
|
+
//NOTE: the error context already reports the service, the api and the version
|
|
52
52
|
return next(133);
|
|
53
53
|
}
|
|
54
54
|
let oauth = true;
|
|
@@ -160,12 +160,16 @@ module.exports = (configuration) => {
|
|
|
160
160
|
//if this is controller route: /key/permission/get, ignore async waterfall response
|
|
161
161
|
if (url_keyACL) {
|
|
162
162
|
if (!req.soajs.uracDriver) {
|
|
163
|
-
if (err && err.message) {
|
|
164
|
-
req.soajs.log.error(err.message);
|
|
165
|
-
}
|
|
166
163
|
if (err && err.name === "OAuth2Error") {
|
|
164
|
+
//NOTE: the code and the message travel with the error, the
|
|
165
|
+
// error context reports both with full attribution
|
|
167
166
|
return next(err);
|
|
168
167
|
}
|
|
168
|
+
//NOTE: the cause is replaced by 158 below, so it is only
|
|
169
|
+
// recoverable from here
|
|
170
|
+
if (err && err.message) {
|
|
171
|
+
req.soajs.log.error(err.message);
|
|
172
|
+
}
|
|
169
173
|
//doesn't work if you are not logged in
|
|
170
174
|
return next(158);
|
|
171
175
|
} else {
|
|
@@ -180,7 +184,8 @@ module.exports = (configuration) => {
|
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
if (err) {
|
|
183
|
-
|
|
187
|
+
//NOTE: the error context already reports the service, the api and
|
|
188
|
+
// the version alongside the code and the message
|
|
184
189
|
return next(err);
|
|
185
190
|
} else {
|
|
186
191
|
let serviceName = data.req.soajs.controller.serviceParams.name;
|
package/package.json
CHANGED
|
@@ -146,6 +146,19 @@ describe("Testing utilities", () => {
|
|
|
146
146
|
done();
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
+
it("errorContext - falls back to service_n and service_v before gotoService resolves them", (done) => {
|
|
150
|
+
// key and keyACL run before gotoService, so serviceParams carries only the
|
|
151
|
+
// raw service_n / service_v at that point
|
|
152
|
+
let r = makeReq(true);
|
|
153
|
+
r.soajs.controller.serviceParams = { "service_n": "urac", "service_v": "3" };
|
|
154
|
+
utils.controllerErrorHandler(154, r, res, null);
|
|
155
|
+
|
|
156
|
+
let ctx = JSON.parse(logged.error[0]);
|
|
157
|
+
assert.strictEqual(ctx.service, "urac");
|
|
158
|
+
assert.strictEqual(ctx.version, "3");
|
|
159
|
+
done();
|
|
160
|
+
});
|
|
161
|
+
|
|
149
162
|
it("logErrors - string error", (done) => {
|
|
150
163
|
utils.logErrors("error", req, res, (error) => {
|
|
151
164
|
done();
|
package/utilities/utils.js
CHANGED
|
@@ -51,8 +51,10 @@ function errorContext(err, req) {
|
|
|
51
51
|
"code": code,
|
|
52
52
|
"msg": msg,
|
|
53
53
|
"method": req.method,
|
|
54
|
+
//NOTE: name and version are resolved by gotoService, the service_n and service_v
|
|
55
|
+
// fallbacks cover the middleware that runs before it, ex: key and keyACL
|
|
54
56
|
"service": serviceParams.name || serviceParams.service_n || null,
|
|
55
|
-
"version": serviceParams.version || null,
|
|
57
|
+
"version": serviceParams.version || serviceParams.service_v || null,
|
|
56
58
|
"api": (serviceParams.parsedUrl && serviceParams.parsedUrl.pathname) || null,
|
|
57
59
|
"url": redactUrl(req.url),
|
|
58
60
|
"ip": req.getClientIP ? req.getClientIP() : null,
|