--
See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/6798e78d-1c46-4f41-b657-16d13a7bc791%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Le 27 oct. 2015 23:53, "AJ Mercer" <ajme...@gmail.com> a écrit :
>
> Not too sure what you are trying to do here,
> but if you are using onerror in application.cfc - it does not work
?
seems to work for me except that i cannot throw custom code ...
my instalation is on Ubuntu. a nginx proxy send request to the lucee vm.
default install i think
throw function and 500 even with errorcode 400
i though that some catalina parameters where to blame.
Thanks for your help
Stéphane
> You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/0v-pmUk8ipU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.
> To post to this group, send email to lu...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAPURtC34W-ZrCpFktJcO17u8BYCmm7inAoAyRt8VLyy9x2Gp4Q%40mail.gmail.com.
<cffunction name="mythrow" access="private" output="false" returntype="void">
<cfargument name="errorCode" type="numeric" default="500" />
<cfargument name="detail" type="string" required="true" hint="message to return to api consumer" />
<cfargument name="message" type="string" default="" />
<cfcontent reset="true" />
<cfif isdefined("arguments.message") and arguments.message neq "">
<cfset arguments.detail=arguments.detail & arguments.message>
</cfif>
<cfheader statuscode="#arguments.errorCode#" statustext="#arguments.detail#" />
<cfabort />
</cffunction>
Page request is aborted
help needed here ...
Stéphane
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/8501b0ae-e562-4d5b-8664-190eef85d3f4%40googlegroups.com.
Stéphane,
Maybe this is an issue with how the request is handled on it's way back from Lucee? IE: a reverse proxy issue?
So, if Lucee is throwing a 400 error and the request then goes through tomcat's web server to IIS or Apache, maybe IIS or Apache is interpreting the 400 error from Lucee and returning a 500 to the end user?
What happens if you remove the web server from your stack? Just hit the tomcat web server directly - usually on port 8888. Do you get a 400 error then?
<cffunction name="mythrow" access="private" output="false" returntype="void">
<cfargument name="errorCode" type="numeric" default="500" />
<cfargument name="detail" type="string" required="true" hint="message to return to api consumer" />
<cfargument name="message" type="string" default="" />
<cfcontent reset="true" />
<cfif isdefined("arguments.message") and arguments.message neq "">
<cfset arguments.detail=arguments.detail & arguments.message>
</cfif>
<cfheader statuscode="#arguments.errorCode#" statustext="#arguments.detail#" />
<!--- <cfabort showerror="#arguments.errorCode# #arguments.detail#" /> --->
<cfscript>
RestSetResponse({"status":"#arguments.errorCode# #arguments.detail#"});
</cfscript>
</cffunction>
Page request is aborted
If you want to write the headers to the browser <cfflush> (or flush; in script) will force the currently defined headers to write. Once you call abort; after that, your headers are already sent and may not be changed.
<cffunction name="mythrow" access="private" output="false" returntype="void">
<cfargument name="errorCode" type="numeric" default="500" />
<cfargument name="detail" type="string" required="true" hint="message to return to api consumer" />
<cfargument name="message" type="string" default="" />
<cfcontent reset="true" />
<cfif isdefined("arguments.message") and arguments.message neq "">
<cfset arguments.detail=arguments.detail & arguments.message>
</cfif>
<cfcontent reset="yes"><cfheader statuscode="#arguments.errorCode#" statustext="#arguments.detail#" /><cfflush /><cfabort showerror="#arguments.errorCode# #arguments.detail#" />
</cffunction>
Frankly, though, you're better off implementing better error handling upstream and letting 500 errors be what they are: server errors. If you want to deliver a 400 or 404, that should be determined before there is ever a chance to throw an exception.
if (structkeyexists(application.bddinfos, ARGUMENTS.id_base) eq 0) {
erreurmsg="wrong id_base";
writeLog(file=application.logname_error, text="#GetFunctionCalledName()# #erreurmsg# #serialize(ARGUMENTS)#");
application.mythrow(errorCode="400", detail="ERREUR #erreurmsg# #serialize(ARGUMENTS)#");
}
--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/ae314d35-ddd9-4e81-aedd-e6be6c3c9d46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
header statuscode="201" statustext="Created";
Stéphane,
The main idea behind the REST spec for creation is that the response provides the URL of the new resource in the Location header. You may respond with an empty structure or provide a data response.
If you want the location header to be exposed to javascript for a cross-domain request, you will also need to add the following header
Access-Control-Expose-Headers: Location
A typical jQuery handling of that header would be:
$.ajax({
type: 'POST',
url:'/api/v1/myhandler',
data: formData,
success: function(data, textStatus, request){
var resource = request.getResponseHeader('location');
$.get(resource).success(
function(data){
return data;
}
);
}}
});
This methodology requires two HTTP requests, which I dislike personally. There’s nothing in the spec that says you can’t respond with data and my personal preference is to respond with the data of the resource created, unless there is a specific reason not to do so (e.g. - the data marshalling for that resource response is done by a separate controller or other resource).
Here’s a good rundown on various thoughts to your question.
http://stackoverflow.com/questions/1829875/is-it-ok-by-rest-to-return-content-after-post
--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/57fcc689-47af-4fd6-80ee-559d2f99a0b3%40googlegroups.com.