Open nwoolls opened 2 years ago
I've managed to workaround this issue in case of 400 Bad Request by using custom error model together with overriding the ApiBehaviorOptions.InvalidModelStateResponseFactory
.
Something like this:
In Program.cs
:
_ = builder.Services
.Configure<ApiBehaviorOptions>(options => options
.InvalidModelStateResponseFactory = CustomInvalidModelStateResponseFactory.OnActionExecuting);
In CustomInvalidModelStateResponseFactory.cs
:
// trimmed for brevity
public static IActionResult OnActionExecuting(ActionContext context)
{
// trimmed for brevity
throw new ApiException(new GenericApiError
{
error_message = "Request model is invalid.",
validation_errors = validationErrors,
});
}
Hi there. First of all, thanks for your time and project!
I am having an issue with the latest stable version of the library (4.5) running on .NET Core 6.0.
Specifically, under some circumstances the
exceptionMessage
JSON property is astring
, and in some cases theexceptionMessage
JSON property is anobject
. This poses issues when parsing the result, especially using C# where we expect to be able to map the property to a specific type.You can reproduce this with the following steps.
From the command line:
Edit
Program.cs
and add:Edit
WeatherForecastController.cs
and add:Run the project.
The following are examples where
exceptionMessage
may either be anobject
or astring
:Example 1 -
exceptionMessage
is anobject
Example 2 -
exceptionMessage
is anobject
Example 3 -
exceptionMessage
is astring
Example 4 -
exceptionMessage
is astring
Any guidance on this would be very much appreciated. Thanks in advance!