diff --git a/wheels/controller/processing.cfm b/wheels/controller/processing.cfm index 27591e17a..990bd5ca8 100644 --- a/wheels/controller/processing.cfm +++ b/wheels/controller/processing.cfm @@ -137,18 +137,11 @@ public void function $callAction(required string action) { if (FileExists(ExpandPath(local.file))) { Throw(object=e); } else { - if ($get("showErrorInformation")) { - Throw( - type="Wheels.ViewNotFound", - message="Could not find the view page for the `#arguments.action#` action in the `#variables.$class.name#` controller.", - extendedInfo="Create a file named `#LCase(arguments.action)#.cfm` in the `views/#LCase(ListChangeDelims(variables.$class.name, '/', '.'))#` directory (create the directory as well if it doesn't already exist)." - ); - } else { - $header(statusCode=404, statustext="Not Found"); - local.template = $get("eventPath") & "/onmissingtemplate.cfm"; - $includeAndOutput(template=local.template); - abort; - } + $throwErrorOrShow404Page( + type="Wheels.ViewNotFound", + message="Could not find the view page for the `#arguments.action#` action in the `#variables.$class.name#` controller.", + extendedInfo="Create a file named `#LCase(arguments.action)#.cfm` in the `views/#LCase(ListChangeDelims(variables.$class.name, '/', '.'))#` directory (create the directory as well if it doesn't already exist)." + ); } } } diff --git a/wheels/dispatch/functions.cfm b/wheels/dispatch/functions.cfm index 6c324171b..8593c4958 100644 --- a/wheels/dispatch/functions.cfm +++ b/wheels/dispatch/functions.cfm @@ -105,10 +105,10 @@ public struct function $findMatchingRoute(required string path, string requestMe // Throw error if no route was found. if (!StructKeyExists(local, "rv")) { - Throw( + $throwErrorOrShow404Page( type="Wheels.RouteNotFound", - message="Wheels couldn't find a route that matched this request.", - extendedInfo="Make sure there is a route setup in your `config/routes.cfm` file that matches the `#arguments.path#` request." + message="Could not find a route that matched this request.", + extendedInfo="Make sure there is a route configured in your `config/routes.cfm` file that matches the `#arguments.path#` request." ); } diff --git a/wheels/global/internal.cfm b/wheels/global/internal.cfm index 40111f7a9..f7020b084 100644 --- a/wheels/global/internal.cfm +++ b/wheels/global/internal.cfm @@ -386,9 +386,13 @@ public string function $routeVariables() { */ public struct function $findRoute() { - // throw an error if a route with this name has not been set by developer in the config/routes.cfm file - if (application.wheels.showErrorInformation && !StructKeyExists(application.wheels.namedRoutePositions, arguments.route)) { - Throw(type="Wheels.RouteNotFound", message="Could not find the `#arguments.route#` route.", extendedInfo="Create a new route in `config/routes.cfm` with the name `#arguments.route#`."); + // Throw error if no route was found. + if (!StructKeyExists(application.wheels.namedRoutePositions, arguments.route)) { + $throwErrorOrShow404Page( + type="Wheels.RouteNotFound", + message="Could not find the `#arguments.route#` route.", + extendedInfo="Make sure there is a route configured in your `config/routes.cfm` file named `#arguments.route#`." + ); } local.routePos = application.wheels.namedRoutePositions[arguments.route]; @@ -1092,4 +1096,19 @@ public string function $buildReleaseZip(string version=application.wheels.versio return local.path; } +/** + * Throw a developer friendly CFWheels error if set (typically in development mode). + * Otherwise show the 404 page for end users (typically in production mode). + */ +public void function $throwErrorOrShow404Page(required string type, required string message, string extendedInfo="") { + if ($get("showErrorInformation")) { + Throw(type=arguments.type, message=arguments.message, extendedInfo=arguments.extendedInfo); + } else { + $header(statusCode=404, statustext="Not Found"); + local.template = $get("eventPath") & "/onmissingtemplate.cfm"; + $includeAndOutput(template=local.template); + abort; + } +} + diff --git a/wheels/view/forms.cfm b/wheels/view/forms.cfm index 80140575b..468b9c53c 100644 --- a/wheels/view/forms.cfm +++ b/wheels/view/forms.cfm @@ -65,12 +65,12 @@ public string function startFormTag( // if we have a route and method, tap if (Len(arguments.route) && StructKeyExists(arguments, "method")) { - // throw a nice wheels error if the developer passes in a route that was not generated - if (application.wheels.showErrorInformation && !StructKeyExists(application.wheels.namedRoutePositions, arguments.route)) { - Throw( + // Throw error if no route was found. + if (!StructKeyExists(application.wheels.namedRoutePositions, arguments.route)) { + $throwErrorOrShow404Page( type="Wheels.RouteNotFound", - message="Route Not Found", - extendedInfo="The route specified `#arguments.route#` does not exist!" + message="Could not find the `#arguments.route#` route.", + extendedInfo="Make sure there is a route configured in your `config/routes.cfm` file named `#arguments.route#`." ); }