mastercontroller 1.3.18 → 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 +22 -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);
|
package/package.json
CHANGED