Azure / Azure/azure-functions-sql-extension
Allow custom error handling on input binding error
- Dominant language
- C#
- Stars
- 130
- Forks
- 71
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 4
Description
I'm using an HTTP-triggered function like this:
```
public static IActionResult GetAllAvailabilityOnDate(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "availability/{datefilter:regex(^\\d{{4}}-\\d{{2}}-\\d{{2}}$)}")] HttpRequest req,
[Sql("SELECT * FROM dbo.Availability a " +
"WHERE a.Date = @DateFilter ",
CommandType = CommandType.Text,
Parameters = "@DateFilter={datefilter}",
ConnectionStringSetting = "DatabaseConnectionString")] IEnumerable res,
string dateFilter,
ILogger log)
{
```
This works all great - until a user provides some bogus input like "0000-00-00". In this case the Function errors out with
System.Private.CoreLib: Exception while executing function: GetAllAvailabilityOnDate. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'res'. Core Microsoft SqlClient Data Provider: Conversion failed when converting date and/or time from character string.
The Function immediately returns a 500 result. However, I would like to be able to insert some custom error handling and for example return a 400-Bad Request instead.
Is this something that's already somehow possible? If not, I would like to make this an enhancement request :)
Contributor guide
Assessment
This issue has not been assessed yet.