Azure Function Host to give a Message in case of invalid URI path:

518 Views Asked by At

Azure Function Host to give a Message in case of invalid URI path:

Hi, I'm using an Azure Function and testing it through Postman.

My requirement is, when we pass the invalid URI path but the correct Host... we are getting Status: 404 Not Found.

But is it possible and is there any way that we can get Status: 400 Bad Request with a message "Invalid URI Path".

Sample Test Case:

https://SampleFunction.azurewebsites.net/api/SampleFunction

When I try with this URL: https://SampleFunction.azurewebsites.net/apia'a\'b"c> I will be getting Status: 404 Not Found. But we are expecting Status:400 with a proper Message.

Please let me know if we can handle this through Azure Function Configurations/Azure Portal Settings.

Thanks in Advance...

1

There are 1 best solutions below

0
Hury Shen On BEST ANSWER

For this requirement, you can do it by proxy. Please refer to my steps below:

1. I have created a function and its url is: https://xxx.azurewebsites.net/api/SampleFunction

2. Go to "Proxies" tab page of the function app and add a proxy like:

enter image description here

3. Add lines of code to your function:

enter image description here

4. After that, when you request the function url with https://SampleFunction.azurewebsites.net/apia'a\'b"cxxxxxxx, it will response 400 with the message you specified.