I have a REST service that either outputs JSON or returns a 404, depending on whether there's a match. In my existing CF11 setup, I can generate a 404 with
<cfthrow errorcode="404">
but this apparently does not work in CF2018 anymore. In order to generate a 404, I need to use Java (as directed here: How can I send HTTP Status Code and a Response messages to the client in ColdFusion?):
<cfscript>
getPageContext()
.getResponse()
.getResponse()
.sendError( JavaCast( 'int', 404 ), "" );
</cfscript>
This works, but this got me curious, so I created a little test page (not a REST service):
<cfparam name="URL.method" default="cfthrow" >
<cfif URL.method IS "cfthrow">
<cftry>
<cfthrow errorcode="404">
<cfcatch></cfcatch>
</cftry>
</cfif>
<cfif URL.method IS "cfheader">
<cfheader statuscode="404">
</cfif>
<cfif URL.method IS "java">
<cfscript>
getPageContext()
.getResponse()
.getResponse()
.sendError( JavaCast( 'int', 404 ), "" );
</cfscript>
</cfif>
I can't get cfthrow to work here, either. But cfheader DOES work, and as expected, the Java one works, too. Can anyone explain why there are all these disparities? FYI, I'm running Win2012/IIS. Thanks.
p.s. With my existing REST service on CF11, I never could get
<cfheader statuscode="404">
to work, either, to generate a 404. In all cases when I say the 404 doesn't work, what returns is a blank page.