Skip to content

Allow custom error handling on input binding error #285

@sebader

Description

@sebader

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<MyResult> 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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions