Azure / Azure/azure-functions-dotnet-worker
FromBodyAttribute throws exception when request is invalid
- Dominant language
- C#
- Stars
- 466
- Forks
- 215
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 7
Description
With the following function signature:
```
public record GenerateReportInput
{
public required IEnumerable Names { get; set; }
public required IEnumerable Field{ get; set; }
public int Val{ get; set; }
}
[Function("GenerateReport")]
public async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
[FromBody] GenerateReportInput body)
```
If a post request is sent without any body following exception is thrown and internal server error 500 is returned:
```
Result: Function 'GenerateReport', Invocation id 'xxxx': An exception was thrown by the invocation.
Exception: System.InvalidOperationException: The type 'GenerateReportInput' is not supported by the 'DefaultFromBodyConversionFeature'
```
Also if the request is sent with empty body following exception is thrown
```
Result: Function 'GenerateReport', Invocation id 'xxxx': An exception was thrown by the invocation.
Exception: System.Text.Json.JsonException: JSON deserialization for type 'GenerateReportInput' was missing required properties, including the following: Names, Field
```
I would expect in both of these cases no exception would be thrown and 400 would be returned.`
Is there any configuration needed to achieve this?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.