Azure / Azure/azure-functions-sql-extension

Allow custom error handling on input binding error

Open
#285 1 comment 1 reaction 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.