Question

I am trying to replace my cferror tag(which was in application.cfm) with onError method (in application.cfc which will replace application.cfm). But I am facing an issue.
The issue is :

For onError, If i tried to display some user friendly message, it is being displayed in the html at the place where the error is occured.
For example, If exception is occured in the footer, then the message is displayed in the footer of the site and everything else(html) on the site is also displayed.
But when i was using cferror tag, If exception is occured, then only that template is being displayed which is specified in cferror tag.

So,
Is there any way to make the onError to work same as cferror tag?
(In sense of displaying user-friendly message)

Thanks.

Était-ce utile?

La solution

What you're describing makes sense. The output buffer is already part-filled with a response for the client.

In your onError method in application.cfc, you ought to be able to use <cfcontent reset=true> to empty the buffer, then you can send whatever response you like.

Autres conseils

Put this in your Application.cfc

<cffunction name="onError" returnType="void" output="true">
    <cfargument name="exception" required="true">
    <cfargument name="eventname" type="string" required="true">
    <cfset var errortext = "">
    <cflog file="myapperrorlog" text="#arguments.exception.message#">
    <cfsavecontent variable="errortext">
    <cfoutput>
    An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
    Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />
    <cfdump var="#arguments.exception#" label="Error">
    <cfdump var="#form#" label="Form">
    <cfdump var="#url#" label="URL">
    </cfoutput>
    </cfsavecontent>
    <cfmail to="emails@yourdomain.com" subject="Error: #arguments.exception.message#" attributeCollection="#request.mailDetails#">
        #errortext#
    </cfmail>
    <cflocation url="errors.cfm">
</cffunction>

Create a generic errors.cfm Page and where you can show some custom Message to the User, You can add whatever message you want to diplay to the user and in the mail, you can add your own email, so everytime the error comes up, you will get an email.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top