The default python template appears to return 200, even when you system.exit(1) or throw an exception. I assume other older templates behave similarly, and that this is expected of the classic watchdog.
However, if the language template you use supports running the new of-watchdog, I think it can return non-200 codes, like 400, 404, etc. You can download these templates using the faas-cli, they're from the openfaas-incubator project and the community.
I just confirmed using the python3-http language/template from openfaas-incubator, and csharp-httprequest from distantcam that non-200 codes can be returned like 400, 404, etc.
This will list available templates:
faas-cli template store list
To install the csharp template I tested with:
faas-cli template store pull distantcam/csharp-httprequest
The OOTB handler for csharp-httprequest can be easily modified like this to return a 400:
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Threading.Tasks;
namespace Function
{
public class FunctionHandler
{
public async Task<(int, string)> Handle(HttpRequest request)
{
var reader = new StreamReader(request.Body);
var input = await reader.ReadToEndAsync();
return (400, $"Hello! Your input was {input}");
}
}
}