OpenBD / openbd-core

The original open source Java powered GPL CFML runtime engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Catch an application error from a remote method call

a1anw2 opened this issue · comments

Craig328 reported this on the mailing list:

So, what I have in a file called remote.cfc was this:

<cffunction name="testcall" access="public" returntype="string">
    <cfargument name="uid" default="0" required="false">
    <cfreturn uid>
</cffunction>

And to test it, I simply called it in a browser window like so:
http://mydevsite.com/cfc/remote.cfc?method=testcall&uid=2

And for that I got the invalid request was attempted message while I had this in my onError method in my Application.cfc:

    <!--- Display an error message if there is a page context. --->
    <cfif NOT (Arguments.EventName IS "onSessionEnd") OR (Arguments.EventName IS "onApplicationEnd")>
        <cfoutput>
        <h2>We apologize but an error has occurred.</h2>
        <p>Technical support has been advised of the error.</p>
        <p>Please <a href="/">click here</a> to return to the home page.</p>
        </cfoutput>

        <cfmail to="craig328@mydevsite.com" from="support@mydevsite.com" subject="Error on mydevsite" type="html">
        <p>Error Event: #Arguments.EventName#</p>
        <p>Error details:<br>
        <cfdump var="#arguments.exception#"></p>
        <p>Form: <cfdump var="#form#"></p>
        <p>Session: <cfdump var="#session#"></p>
        </cfmail>
    <cfelse>
        <cfdump>
    </cfif>
    <cfabort>
</cffunction>

As I mentioned, the call to the method should error when it's set to public like it is...I was just curious why I wasn't catching the error is all. In truth, I'll be the only one calling this method from a mobile app I'm building...but I don't like having someone able to make a call to my site and not being able to handle it gracefully.

I have an Application.cfc here:

<cfcomponent>
<cfscript>
this.name = "apptest";

function onError(catchdata, eventname){
    Console( "onError()" );
}
</cfscript>
</cfcomponent>

When i declare this, the onError() gets triggered when the error happens. So i would take a look at your setup and make sure your Application.cfc is in the right place.

But it works as it should.