I've written a sample CF REST API (CF 2018) to return user details via an API. I've returned the data based on my authentication logic successfully; however, I'd like to send a status code (i.e. 401, 400) upon failures.
The API uses the IIS as a webserver; hence the responses sent to the users are returned via IIS. When the errors are thrown within the API code using <cfthrow errorcode="401" message="test error">
(non 200 status), the responses are returned as HTML from IIS via postman. Please see the screenshot of the postman.
I want to send the responses (non 200 status codes) to the users in JSON format with my custom error message. Is there a way of doing this while having IIS in place?
Do I have to have some IIS rules in place, or is there any other way of achieving this?
I've tried using restSetResponse()
as well, resulting in the same IIS response.