moving the discussion here as jira is not the best place for discussions
LDEV-4175 CFHTTP add a success=true/false to the result (same as throwOnError)
My initial idea was to keep this simple, simply adding a success=true|false
which reflects whether an exception would be thrown if throwOnError=true
you can see the underlying java code in question here
Currently, any responses in the 200-299 range trigger an error, or responses that fail without a status code, which @isapir pointed out then populates a status_code
of 0, so you end up some boilerplate if you donāt want to be throwing a costly exception ( generating stacktraces has a little overhead, depending on how deeply nested your code is etc )
@Brad_Wood and others asked about the logic here and whether 401 responses are successful, they are client errors and need special handling anyway
This is just meant to be an easy way to access the existing cfml business rules to check if the response wasnāt typically ok and may need additional handling, without having to wrap the code in a try catch
currently, when throwOnError=false
, you need to write the following to match that behavior, this is just about reducing a little boiler plate, itās not mandatory to use this, itās just an option
<h1>throwOnError=true</h1>
<cftry>
<cfhttp url="http://missing.luce1e.org" result="result" throwOnError=true></cfhttp>
<cfcatch>
// check and handle the 0 or 401 etc
</cfcatch>
</cftry>
// just keep on coding, check it's json etc
<h1>throwOnError=false, DIY</h1>
<cfhttp url="http://missing.luce1e.org" result="result"></cfhttp>
<cfif result.status_code gte 200
and result.status_code lte 299>
// definately ok
<cfelseif result.status_code eq 0 >
// really failed expletives (censored)
<cfelse>
// may needs extra handling, 401 etc
</cfif>
vs
<h1>throwOnError=false, with result.success</h1>
<cfhttp url="http://missing.luce1e.org" result="result"></cfhttp>
<cfif result.success>
// definately ok
<cfelseif result.status_code eq 0>
// really failed expletives (censored)
<cfelse>
// may needs extra handling, 401 etc
</cfif>
some examples (with and without dump, as that obviously is expensive too!)
erghhh, itās all quite messy infact