mastercontroller 1.3.17 → 1.3.19
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/MasterRouter.js +47 -2
- package/package.json +1 -1
package/MasterRouter.js
CHANGED
|
@@ -763,16 +763,36 @@ class MasterRouter {
|
|
|
763
763
|
try{
|
|
764
764
|
Control = require(path.join(currentRoute.root, 'app', 'controllers', `${tools.firstLetterlowercase(requestObject.toController)}Controller`));
|
|
765
765
|
}catch(e){
|
|
766
|
+
// Check if this is a "file not found" error vs a loading error
|
|
767
|
+
const isModuleNotFound = e.code === 'MODULE_NOT_FOUND' &&
|
|
768
|
+
e.message.includes(`${tools.firstLetterlowercase(requestObject.toController)}Controller`);
|
|
769
|
+
|
|
770
|
+
if (!isModuleNotFound) {
|
|
771
|
+
// Controller file exists but has an error (syntax error, bad require, etc.)
|
|
772
|
+
// Surface the actual error
|
|
773
|
+
throw e;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Try uppercase variant
|
|
766
777
|
try{
|
|
767
778
|
Control = require(path.join(currentRoute.root, 'app', 'controllers', `${tools.firstLetterUppercase(requestObject.toController)}Controller`));
|
|
768
779
|
}catch(e2){
|
|
769
|
-
//
|
|
780
|
+
// Check if this is also a "file not found" error
|
|
781
|
+
const isModuleNotFound2 = e2.code === 'MODULE_NOT_FOUND' &&
|
|
782
|
+
e2.message.includes(`${tools.firstLetterUppercase(requestObject.toController)}Controller`);
|
|
783
|
+
|
|
784
|
+
if (!isModuleNotFound2) {
|
|
785
|
+
// Controller file exists but has an error - surface it
|
|
786
|
+
throw e2;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// Controller truly not found - show generic error
|
|
770
790
|
const error = handleControllerError(
|
|
771
791
|
new Error(`Controller not found: ${requestObject.toController}Controller`),
|
|
772
792
|
requestObject.toController,
|
|
773
793
|
requestObject.toAction,
|
|
774
794
|
requestObject.pathName,
|
|
775
|
-
currentRoute.routeDef
|
|
795
|
+
currentRoute.routeDef
|
|
776
796
|
);
|
|
777
797
|
|
|
778
798
|
sendErrorResponse(requestObject.response, error, requestObject.pathName);
|
|
@@ -908,7 +928,32 @@ class MasterRouter {
|
|
|
908
928
|
throw new TypeError('Request object must have a valid response property');
|
|
909
929
|
}
|
|
910
930
|
|
|
931
|
+
// Normalize pathName from various request object formats
|
|
911
932
|
if (!rr.pathName || typeof rr.pathName !== 'string') {
|
|
933
|
+
// Try to extract pathName from standard HTTP request properties
|
|
934
|
+
if (rr.request.url) {
|
|
935
|
+
// Handle full URL or path with query string (Node.js http, Express)
|
|
936
|
+
try {
|
|
937
|
+
// Try parsing as full URL first
|
|
938
|
+
const url = new URL(rr.request.url, `http://${rr.request.headers?.host || 'localhost'}`);
|
|
939
|
+
rr.pathName = url.pathname;
|
|
940
|
+
} catch (e) {
|
|
941
|
+
// Fallback: treat as relative path, strip query string
|
|
942
|
+
rr.pathName = rr.request.url.split('?')[0];
|
|
943
|
+
}
|
|
944
|
+
} else if (rr.request.path) {
|
|
945
|
+
// Express-style request.path
|
|
946
|
+
rr.pathName = rr.request.path;
|
|
947
|
+
} else if (rr.request.pathname) {
|
|
948
|
+
// Alternative property name
|
|
949
|
+
rr.pathName = rr.request.pathname;
|
|
950
|
+
} else {
|
|
951
|
+
throw new TypeError('Request object must have a valid path (url, path, pathname, or pathName property)');
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// Validate that we now have a valid pathName
|
|
956
|
+
if (typeof rr.pathName !== 'string') {
|
|
912
957
|
throw new TypeError('Request object must have a valid pathName');
|
|
913
958
|
}
|
|
914
959
|
|
package/package.json
CHANGED