Errors array in ModelState contain exception =null but ErrorMessage is filled, using Microsoft.AspNetCore.Mvc C#

44 views Asked by At

I'm using a REST API app in .NET 5.

I have this custom action filter

public class HttpErrorHandlerAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext actionContext) 
    { 
        if (actionContext.ModelState.IsValid == false)
        {
            foreach (var state in actionContext.ModelState)
            {
                if (state.Value.Errors.Count != 0)
                {
                    // .....
                }
            }
        }
    }
}

The function OnActionExecuting hit as I send wrong data so it suppose to fail on converting to the response type.

Errors contains element with the error as the follow:

ErrorMessage: Couldn't convert..

Exception: null

I want the exception to be filled so I could filter on the exception type.

How can I configure this?

Thanks

0

There are 0 answers