cftry catch not returning withStatus code

49 views
Skip to first unread message

Tim Vanderlois

unread,
Aug 26, 2015, 11:37:14 AM8/26/15
to Taffy Users
I have added cftry cfcatch around my get method. For testing I intentionally broke the get function and my cfcatch executes; however the cfcatch has code to return: rep("some message").withStatus(400, "some message")

but instead on my consuming end I'm getting a status 500 with message "error". Why would I not get the 400 status?

Matt Quackenbush

unread,
Aug 26, 2015, 11:43:12 AM8/26/15
to taffy...@googlegroups.com
My guess is that there is code in the catch block that is in fact throwing an exception itself. Can you show us the code?  :-)

On Wed, Aug 26, 2015 at 10:37 AM, Tim Vanderlois <tim.van...@gmail.com> wrote:
I have added cftry cfcatch around my get method. For testing I intentionally broke the get function and my cfcatch executes; however the cfcatch has code to return: rep("some message").withStatus(400, "some message")

but instead on my consuming end I'm getting a status 500 with message "error". Why would I not get the 400 status?

--
You received this message because you are subscribed to the Google Groups "Taffy Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to taffy-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Vanderlois

unread,
Aug 26, 2015, 11:59:10 AM8/26/15
to taffy...@googlegroups.com
Good thought. My cfcatch uses a cfinclude. For testing the only statement now in the cfinclude is: <cfreturn  rep("test").withStatus(400,"test")>

No issues when NOT using the cfinclude, but there are issues using the cfinclude.

Another note on the cfinlude: i had a cfmail tag that did execute so I know the cfinclude is getting included correctly. 

--
You received this message because you are subscribed to a topic in the Google Groups "Taffy Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/taffy-users/B4t-SwKljkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to taffy-users...@googlegroups.com.

Tim Vanderlois

unread,
Aug 26, 2015, 12:05:24 PM8/26/15
to taffy...@googlegroups.com
Following returns status 400
<cfcatch type="any">
  <cfreturn  rep("test").withStatus(400,"test")>
</cfcatch>

Following returns status 500
<cfcatch type="any">
  <cfinclude template="/common/cfm/apiCatch.cfm">
</cfcatch>

apiCatch.cfm
<cfreturn  rep("test").withStatus(400,"test")>
On Wed, Aug 26, 2015 at 10:42 AM, Matt Quackenbush <quack...@gmail.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "Taffy Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/taffy-users/B4t-SwKljkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to taffy-users...@googlegroups.com.

Matt Quackenbush

unread,
Aug 26, 2015, 12:07:07 PM8/26/15
to taffy...@googlegroups.com
I'm guessing that you're attempting to reference something in the include that is out of scope, throwing the exception. What do your logs say?

Tim Vanderlois

unread,
Aug 26, 2015, 12:22:27 PM8/26/15
to Taffy Users
Perhaps I cannot use the mixin rep() in the cfinlude...

{
   "stacktrace": [
      {
         "RAW_TRACE": "\tat cfapi2ecfc627712383$funcONREQUEST.runFunction(/var/www/tvanderl/safetyDataSheets/wwwroot/api/taffy3_0_0/core/api.cfc:324)",
         "ID": "CF_DOTRESOLVER",
         "TEMPLATE": "/var/www/tvanderl/safetyDataSheets/wwwroot/api/taffy3_0_0/core/api.cfc",
         "LINE": 324,
         "TYPE": "CFML",
         "COLUMN": 0
      
}
   ]
,
   "tagContext": "/var/www/tvanderl/safetyDataSheets/wwwroot/api/taffy3_0_0/core/api.cfc [Line 324]",
   "detail": "",
   "error": "Element result is undefined in _TAFFYREQUEST."

Adam Tuttle

unread,
Aug 26, 2015, 12:54:53 PM8/26/15
to Taffy Users
Without more of your code to go on, it's hard to say for sure what the root of the problem is.

Using a mixin inside a function is something I've never tried before, but I wouldn't be surprised if ACF is messing that up somehow. Can you move the mixin up to the component pseudoconstructor (outside of the methods, inside the component) and make it (your mixin) just a set of functions that can be called?

Alternatively, use a base class. That's the more traditional method of code sharing with objects. If you make base.cfc that extends taffy.core.representation; and then your resources extend base, then taffy's functionality will still work and you can share the functionality in base across any number of objects.

Adam

Tim Vanderlois

unread,
Aug 26, 2015, 3:08:42 PM8/26/15
to Taffy Users
Could I put a function in my Application.cfc that extends taffy.core.api - if so how would I invoke from a resource?

If not I may use a base class as suggested. 

My initial goal was to standardize catching any api error throughout all api's, cfinclude would have been nice, but ultimately I should have known better using cfinclude within a cfc.

Adam Tuttle

unread,
Aug 26, 2015, 4:20:23 PM8/26/15
to Taffy Users
No, functions in Application.cfc are not available to resource methods.
Reply all
Reply to author
Forward
0 new messages