ColdFusion REST Services not allowing a struct to be sent back in "content" when status code is 4xx
- August 11, 2021
- 2 replies
- 1652 views
I am using CF REST Services and we would like to send back a detailed error struct when a requestor submits data that does not pass our internal validation check. I am using setRestResponse to manipulate the status code (which works fine on all accounts). However when someone fails validation I would like to send a struct back to the user with a 400 or a 401. My research lead me to putting the struct in the "content" part of my return struct to setRestResponse however when I do that, I get the correct statuscode but not the JSON struct of the error detail.
One thing Im observing is my api seems to be returning HTML, even though I have set the "produces" attribute of my function to "application/json". I have also set the function to void since we are using setRestResponse. Can you help me figure out how to send back an error detail struct with a 400 error? What exactly needs to happen to make the API respond with JSON beyond what Ive done already?
Ive included a snippet of my code.
