I had this code in Azure Function where I have used .NET 6.0:
catch (Exception ex)
{
log.LogError($"Data Access Failed: {ex.Message}");
return new NotFoundObjectResult(ex.Message);
}
I upgraded the Azure Function to .NET 7.0 Isolated Worker Model. What is the equivalent in .NET 7.0 isolated worker model to return the HTTP status code of no data found.
You can use something like below code(
HttpStatusCode.NotFound
) which gives 404 status code:Code:
Output:
In
response.WriteString
written my own message, there you can send exception message