root/coldbox/trunk/src/system/services/exceptionService.cfc @ 740

Revision 740, 4.9 kB (checked in by lmajano, 6 years ago)

Ticket #180
Customizable event name finalized ahead of schedule

Line 
1<!-----------------------------------------------------------------------
2********************************************************************************
3Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
4www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com
5********************************************************************************
6
7Author      :   Luis Majano
8Date        :   January 18, 2007
9Description :
10        This service takes cares of exceptions
11
12Modification History:
1301/18/2007 - Created
14----------------------------------------------------------------------->
15<cfcomponent name="exceptionService" output="false" hint="The exception service">
16
17<!------------------------------------------- CONSTRUCTOR ------------------------------------------->
18
19        <cffunction name="init" access="public" output="false" returntype="exceptionService" hint="Constructor">
20                <cfargument name="controller" type="any" required="true">
21                <cfscript>
22                        variables.controller = arguments.controller;
23                        return this;
24                </cfscript>
25        </cffunction>
26
27<!------------------------------------------- PUBLIC ------------------------------------------->
28
29        <cffunction name="ExceptionHandler" access="public" hint="I handle a framework/application exception. I return a framework exception bean" returntype="any" output="false">
30                <!--- ************************************************************* --->
31                <cfargument name="Exception"     type="any"     required="true"  hint="The exception structure. Passed as any due to CF glitch">
32                <cfargument name="ErrorType"     type="string"  required="false" default="application">
33                <cfargument name="ExtraMessage"  type="string"  required="false" default="">
34                <!--- ************************************************************* --->
35                <cfscript>
36                var BugReport = "";
37                var ExceptionBean = controller.getPlugin("beanFactory").create("coldbox.system.beans.exceptionBean").init(errorStruct=arguments.Exception,extramessage=arguments.extraMessage,errorType=arguments.ErrorType);
38                var requestContext = controller.getRequestService().getContext();
39                // Test Error Type
40                if ( not reFindnocase("(application|framework)",arguments.errorType) )
41                        arguments.errorType = "application";
42
43                if ( arguments.ErrorType eq "application" ){
44                        //Run custom Exception handler if Found, else run default
45                        if ( controller.getSetting("ExceptionHandler") neq "" ){
46                                try{
47                                        requestContext.setValue("ExceptionBean",ExceptionBean);
48                                        controller.runEvent(controller.getSetting("Exceptionhandler"));
49                                }
50                                catch(Any e){
51                                        ExceptionBean = controller.getPlugin("beanFactory").create("coldbox.system.beans.exceptionBean").init(errorStruct=e,extramessage="Error Running Custom Exception handler",errorType="application");
52                                        controller.getPlugin("logger").logErrorWithBean(ExceptionBean);
53                                }
54                        }
55                        else{
56                                controller.getPlugin("logger").logErrorWithBean(ExceptionBean);
57                        }
58                }
59                //return
60                return ExceptionBean;
61                </cfscript>
62        </cffunction>
63
64        <cffunction name="renderBugReport" access="public" hint="Render a Bug Report." output="false" returntype="Any">
65                <cfargument name="ExceptionBean" type="any" required="true">
66                <cfset var BugReport = "">
67                <cfset var Exception = arguments.ExceptionBean>
68                <cfset var Event = controller.getRequestService().getContext()>
69                <!--- test for custom bug report --->
70                <cfif Exception.getErrortype() eq "application" and controller.getSetting("CustomErrorTemplate") neq "">
71                        <cftry>
72                                <!--- Place exception in the requset Collection --->
73                                <Cfset Event.setvalue("ExceptionBean",Exception)>
74                                <!--- Save the Custom Report --->
75                                <cfsavecontent variable="BugReport"><cfinclude template="/#controller.getSetting("AppMapping")#/#controller.getSetting("CustomErrorTemplate")#"></cfsavecontent>
76                                <cfcatch type="any">
77                                        <cfset Exception = ExceptionHandler(cfcatch,"Application","Error creating custom error template.")>
78                                        <!--- Save the Bug Report --->
79                                        <cfsavecontent variable="BugReport"><cfinclude template="../includes/BugReport.cfm"></cfsavecontent>
80                                </cfcatch>
81                        </cftry>
82                <cfelse>
83                        <!--- Save the Bug Report --->
84                        <cfsavecontent variable="BugReport"><cfinclude template="../includes/BugReport.cfm"></cfsavecontent>
85                </cfif>
86                <cfreturn BugReport>
87        </cffunction>
88       
89<!------------------------------------------- ACCESSOR/MUTATORS ------------------------------------------->
90
91        <cffunction name="getcontroller" access="public" output="false" returntype="any" hint="Get controller">
92                <cfreturn variables.controller/>
93        </cffunction>
94       
95        <cffunction name="setcontroller" access="public" output="false" returntype="void" hint="Set controller">
96                <cfargument name="controller" type="any" required="true"/>
97                <cfset variables.controller = arguments.controller/>
98        </cffunction>   
99       
100<!------------------------------------------- PRIVATE ------------------------------------------->
101
102
103</cfcomponent>
Note: See TracBrowser for help on using the browser.