Hi there. I am trying out AutoWrapper 5.0 in an attempt to work around the problem described in issue #133.
With AutoWrapper 5.0, I am running into the following problem: when passing in a status code (e.g. 400) to the ApiException constructor, the resulting JSON object indicates the status code is 500.
You can reproduce this with the following steps.
From the command line:
dotnet --version
6.0.101
mkdir autowrapper-apiexception-issue
cd autowrapper-apiexception-issue/
dotnet new webapi
dotnet add package AutoWrapper.Core --version 5.0.0-rc-03
Edit Program.cs and add:
public class InputModel
{
[Required(AllowEmptyStrings = false)]
public string? FirstName { get; set; }
}
[HttpPost]
public IActionResult Post(InputModel inputModel)
{
if (inputModel.FirstName == "foo")
{
throw new ApiException("An error occurred - throwing ApiException", StatusCodes.Status400BadRequest);
}
if (inputModel.FirstName == "bar")
{
throw new ApiProblemDetailsException("An error occurred - throwing ApiProblemDetailsException", StatusCodes.Status400BadRequest);
}
return StatusCode(StatusCodes.Status201Created);
}
Run the project.
The following are examples where throwing exceptions may result in a status code of 500 or 400.
Hi there. I am trying out AutoWrapper 5.0 in an attempt to work around the problem described in issue #133.
With AutoWrapper 5.0, I am running into the following problem: when passing in a status code (e.g.
400
) to theApiException
constructor, the resulting JSON object indicates the status code is500
.You can reproduce this with the following steps.
From the command line:
Edit
Program.cs
and add:Run the project.
The following are examples where throwing exceptions may result in a status code of
500
or400
.Example 1 - Status Code is
500
Example 2 - status code is
400
This may be by-design due to the new defaults in AutoWrapper 5.0, but some clarity on this would still be much appreciated.