Catch error on application.cfc based on current directory

I’m searching for a solution to catch errors based on the current directory. I would like to display an error message depending on the current directory which get an error.
The Application.cfc script works fine, could you support me or telling me what would be the best solution to add this information? Thank you for your support and time.

Adding soemthing like that, but not sure if Application.cfc recognized the path which got the error #GetFileFromPath("#GetCurrentTemplatePath()#")#

<cfif CGI.SCRIPT_NAME CONTAINS "home.cfm">
	<cfargument	name="Exception" type="any" required="true" />
	<cfargument name="EventName" type="string" required="false" default="" />
	<cfset infoStruct.CGI = CGI>
	<cfoutput><h1>Something went wrong. Please open a ticket</h1></cfoutput>
	<cfset infoStruct = StructNew()>
			   <cfdump var="#Exception#">
			   <cfdump var="#infoStruct#">									   

<cfelseif CGI.SCRIPT_NAME CONTAINS "support.cfm">
	<cfargument	name="Exception" type="any" required="true" />
	<cfargument name="EventName" type="string" required="false" default="" />
	<cfset infoStruct.CGI = CGI>
	<cfoutput><h1>Something went wrong. Please use the following url: www.xxxxxxxx.com</h1></cfoutput>
	<cfset infoStruct = StructNew()>
			   <cfdump var="#Exception#">
			   <cfdump var="#infoStruct#">
<cfelse>
other errors 
</cfif>

The Application.cfc:

<cfcomponent displayname="Application" output="true" hint="Application cfc">

               
                <cffunction name="Application_End"> 
                               <cfargument name="ApplicationScope" required=true/> 
                               <cflog file="#This.Name#" type="Information" 
                                               text="Application #Arguments.ApplicationScope.applicationname# Ended" > 
                </cffunction>


                
                <cffunction name="OnErrors" access="public" returntype="void" output="true" hint="Fires when an exception occures that is not caught by a try/catch.">
					
					<!--- Catch errors arguments--->
					
					<cfargument	name="Exception" type="any" required="true" />
					<cfargument name="EventName" type="string" required="false" default="" />
					
					<cfset infoStruct.CGI = CGI>
						
						<cfoutput>
					    <h1>Something went wrong</h1>
					    <h4>furhter text depending on the page name</h4>
						</cfoutput>
							   

							   
                               <cfset infoStruct = StructNew()>
                                                               <cfdump var="#Exception#">
                                                               <cfdump var="#infoStruct#">


							   <!--- E-Mail notification--->
                               <cftry> 
								   <cfset infoStruct.CGI = CGI>											
								   
								   <cfmail to="xxxxxx@xxxxxx.com" from="xxxxxx@xxxxxx.com" subject="error.cfm" type="html">
												   <cfdump var="#Exception#">
												   <cfdump var="#infoStruct#">
								   </cfmail>
                               </cftry>
							   
							   
			        <cfreturn />
                </cffunction>

Let’s see… I don’t understand exactly why you are trying to do it that way. I’m sure you have your reasons. So here are my thoughts: I would set up a simple cferror with a template in the application.cfc, and then you can do what ever you want within that error-template. See https://www.bennadel.com/blog/932-ask-ben-handling-errors-with-coldfusion-cferror.htm

In the error-template you should be able to make conditionals on behalf cgi.script_name the same way, and email notifications work also fine. You can dump session variables, formfields, url-variables and many more. I’ve even done mobile text messaging that way for application blocking errors. Wouldn’t that work in your scenario?

@Retooo, I think Andreas thought will help to your issue. Please try that too.

Hi Andreas thank you for the help and support. Sorry for the late response, it took time to do it.
case is solve thank you again for the recommendation.

1 Like