0
votes

When we setup an Azure Function (3) with bind parameter of DateTime, if someone calling the API has the wrong DateTime they just get a "500 Internal Server Error".

In the backend we get an error like this:

System.Private.CoreLib: Exception while executing function: XXX. Microsoft.Azure.WebJobs.Host: One or more errors occurred. (Exception binding parameter 'dateTime'). System.Private.CoreLib: String '2020-5-13T12:0t' was not recognized as a valid DateTime.

I want to return a BadRequestObject with the specific parameters at fault.

The only way I can find to do this is make all parameters strings, and then try and parse them in code, and through an error if there is an issue.

Is there a better way?

1

1 Answers

-1
votes

Below code helps you in returning the 500 Internal server error to BadRequestObject with the specified parameters

[Microsoft.AspNetCore.Mvc.NonAction]
public  virtual System.Web.Http.BadRequestErrorMessageResult BadRequest (string message);

Check apicontroller.badrequestmethod for further details.

Update:

Also, I would like to suggest you, use ArgumentException, ArgumentNullException, and ArgumentOutOfRangeException.