Copy link to clipboard
Copied
Hey people. I have the following cferror code for my custom error messages, but it won't work for missng templates. Not sure why have search high and low on the adobe forums and came out empty. Any help would be great.
=== Application.cfc ===
<cfcomponent>
<cferror type="Request" template="errormessage.cfm"
mailto="sample@gmail.com">
<cferror type="Exception" template="errormessage.cfm"
mailto="sample@gmail.com">
<cferror type="Validation" template="errormessage.cfm"
mailto="sample@gmail.com">
<cffunction name="onRequestStart">
<cflogin>
<cfif IsDefined("FORM.Login_btn")>
<cfquery name="qLogin" datasource="poll">
SELECT UserLogin, UserPassword, UserRoleID
FROM Users
WHERE UserLogin = <cfqueryparam value="#cflogin.Name#" cfsqltype="cf_sql_varchar">
AND UserPassword = <cfqueryparam value="#cflogin.Password#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfif cflogin.name IS "#qLogin.UserLogin#" AND cflogin.password IS "#qLogin.UserPassword#">
<cfloginuser name="#cflogin.name#"
password="#cflogin.password#"
roles="#qLogin.UserRoleID#">
<cfelse>
<cfset request.errorMsg = "Incorrect login; please try again">
<cfinclude template="../login/login.cfm">
<cfabort />
</cfif>
<cfelse>
<cfinclude template="../login/login.cfm">
<cfabort />
</cfif>
</cflogin>
</cffunction>
</cfcomponent>
=== errormessage.cfm ===
<!---
Filename: ErrorException.cfm
Created by: Nate Weiss (NMW)
Please Note: Included via <CFERROR> in Application.cfc
--->
<html>
<head><title>Error</title></head>
<body>
<!--- Display sarcastic message to poor user --->
<h2>OOPS Something happened</h2><br><br>
Not sure what went wrong, but the admin has been notified about this problem and we will have if fixed soon. <br>
Sorry for the inconvenience.
<!--- Send an email message to site administrator --->
<!--- (or whatever address provided to <cferror>) --->
<cfif ERROR.mailTo neq "">
<cfmail to="#ERROR.mailTo#" from="errorsender@orangewhipstudios.com"
subject="Error on Page #ERROR.Template#">
Error Date/Time: #ERROR.dateTime#
User’s Browser: #ERROR.browser#
URL Parameters: #ERROR.queryString#
Previous Page: #ERROR.HTTPReferer#
------------------------------------
#ERROR.diagnostics#
</cfmail>
</cfif>
</body>
</html>
Thanks in advanced
Copy link to clipboard
Copied
When you say missing templates, do you mean ones that are referred to on a URL, or when using CFINCLUDE (or both)?
If it's from the URL, then odds-on the web server is checking whether the file exists before passing processing to CF, and if it doesn't exist, it uses its own 404 handler.
--
Adam
PS: I'd probably use onError() and onMissingTemplate() if I was using Application.cfc. To me CFERROR is a bit of an old artefact of the pre-event-driven days of Application.cfm. Either will work, but the event-handler approach is more inkeeping with the intents of Application.cfc.