1

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.enter image description here

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.

akashb
  • 111
  • 6
  • 1
    have you tried this? https://stackoverflow.com/a/63302681/1636917 – Miguel-F Nov 29 '21 at 14:51
  • Thanks, @Miguel-F for this. I've tried this and worked like a charm. If you want you can post as an answer and I'll accept it. Cheers once again! – akashb Nov 30 '21 at 04:00
  • 1
    Glad that worked for you. Instead of posting an answer I will indicate that this question can be closed as already having an answer (to the link provided). Thanks. – Miguel-F Nov 30 '21 at 12:40

0 Answers0