PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/events/onerror.cfm

http://cfwheels.googlecode.com/
ColdFusion | 74 lines | 69 code | 5 blank | 0 comment | 20 complexity | 6953d83bff8ff1e98d61450e7dcc2326 MD5 | raw file
 1<cffunction name="onError" returntype="void" access="public" output="true">
 2	<cfargument name="exception" type="any" required="true">
 3	<cfargument name="eventName" type="any" required="true">
 4	<cfscript>
 5		var loc = {};
 6
 7		// In case the error was caused by a timeout we have to add extra time for error handling.
 8		// We have to check if onErrorRequestTimeout exists since errors can be triggered before the application.wheels struct has been created.
 9		loc.requestTimeout = 70;
10		if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "onErrorRequestTimeout"))
11			loc.requestTimeout = application.wheels.onErrorRequestTimeout;
12		$setting(requestTimeout=loc.requestTimeout);
13
14		loc.returnValue = $simpleLock(execute="$runOnError", executeArgs=arguments, name="wheelsReloadLock", type="readOnly", timeout=180);
15	</cfscript>
16	<cfoutput>
17		#loc.returnValue#
18	</cfoutput>
19</cffunction>
20
21<cffunction name="$runOnError" returntype="string" access="public" output="false">
22	<cfargument name="exception" type="any" required="true">
23	<cfargument name="eventName" type="any" required="true">
24	<cfscript>
25		var loc = {};
26
27		if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "initialized"))
28		{
29			if (application.wheels.sendEmailOnError && Len(application.wheels.errorEmailAddress))
30			{
31				loc.mailArgs = {};
32				$args(name="sendEmail", args=loc.mailArgs);
33				if (StructKeyExists(application.wheels, "errorEmailServer") && Len(application.wheels.errorEmailServer))
34					loc.mailArgs.server = application.wheels.errorEmailServer;
35				loc.mailArgs.from = application.wheels.errorEmailAddress;
36				loc.mailArgs.to = application.wheels.errorEmailAddress;
37				loc.mailArgs.subject = application.wheels.errorEmailSubject;
38				loc.mailArgs.type = "html";
39				loc.mailArgs.tagContent = $includeAndReturnOutput($template="wheels/events/onerror/cfmlerror.cfm", exception=arguments.exception);
40				StructDelete(loc.mailArgs, "layouts", false);
41				StructDelete(loc.mailArgs, "detectMultiPart", false);
42				$mail(argumentCollection=loc.mailArgs);
43			}
44	
45			if (application.wheels.showErrorInformation)
46			{
47				if (StructKeyExists(arguments.exception, "rootCause") && Left(arguments.exception.rootCause.type, 6) == "Wheels")
48					loc.wheelsError = arguments.exception.rootCause;
49				else if (StructKeyExists(arguments.exception, "cause") && StructKeyExists(arguments.exception.cause, "rootCause") && Left(arguments.exception.cause.rootCause.type, 6) == "Wheels") 
50					loc.wheelsError = arguments.exception.cause.rootCause;
51				if (StructKeyExists(loc, "wheelsError"))
52				{
53					loc.returnValue = $includeAndReturnOutput($template="wheels/styles/header.cfm");
54					loc.returnValue = loc.returnValue & $includeAndReturnOutput($template="wheels/events/onerror/wheelserror.cfm", wheelsError=loc.wheelsError);
55					loc.returnValue = loc.returnValue & $includeAndReturnOutput($template="wheels/styles/footer.cfm");
56				}
57				else
58				{
59					$throw(object=arguments.exception);
60				}
61			}
62			else
63			{
64				$header(statusCode=500, statusText="Internal Server Error");
65				loc.returnValue = $includeAndReturnOutput($template="#application.wheels.eventPath#/onerror.cfm", exception=arguments.exception, eventName=arguments.eventName);
66			}
67		}
68		else
69		{
70			$throw(object=arguments.exception);
71		}
72	</cfscript>
73	<cfreturn loc.returnValue>
74</cffunction>