Skip to main content
Participant
May 24, 2009
Question

OnError() function in web service: impossible?

  • May 24, 2009
  • 1 reply
  • 789 views

Hi,

Context: A ColdFusion web service with application.cfc and OnError() function.

I want the OnError function to log and email me when exceptions occur in web service but for some reason OnError() is never fired in such a case.

It's weird because it works if a .cfm page is called instead of a .cfc!

Is it a standard behaviour with CF webservice? Is there a workaround?

Thanks

This topic has been closed for replies.

1 reply

Inspiring
May 24, 2009

I'm guessing your application.cfc does not play with your webservice cfc at all.

The workaround is cftry/cfcatch for whatever function is being invoked as the webservice.

salvo2Author
Participant
May 25, 2009

Hi Dan,

Thank you for reading and suggesting. The fact is I would like to use onError() for what it is supposed to provide - and also to understand the mechanism.

My onRequestStart() sets request variables to bar.cfc so application.cfc globally plays fine with the webservice cfcs. Well... except for error handling

I found that if exception occurs in application.cfc it is actually caught by onError().

But if exception occurs in webservice cfcs then it is not caught by onError() and a ugly SOAP error is sent to consumer instead.

Here are my application.cfc and bar.cfc webservice components. They are pretty simple so I don't see why onError() is not fired:


<cfcomponent displayname="Application" output="false">


    <cfscript>
        this.Name                = "foo";
        this.applicationTimeOut    = CreateTimeSpan(0,1,0,0);
        this.sessionManagement    = false;
        this.setClientCookies    = false;
        this.clientManagement    = false;
        this.scriptProtect        = "all";
    </cfscript>


    <cffunction name="onApplicationStart" access="public" output="false">

        <cfset application.foo= "foo" />

    </cffunction>

    <cffunction name="onRequestStart" access="public" output="true">

        <cfargument name="targetPage" type="string" required="true" />

    </cffunction>

    <cffunction name="onError" access="public" returnType="void" output="true">

        <cfargument name="Exception" required="true" />
        <cfargument name="EventName" type="string" required="true" />

        <cfmail from="toto" to="admin@admin.com" subject="error">
            error
        </cfmail>

    </cffunction>

</cfcomponent>



<cfcomponent displayname="bar">

    <cffunction name="test" access="remote" returntype="cpTest" output="false">

     <!--- Throws an exception as b does not exist. This must be caught by onError() but it is not --->                   

     <cfset a = b />

     </cffunction>


</cfcomponent>

Any clue?

-Salvo