TempleOS
TempleOS
Explore posts from servers
CC#
Created by TempleOS on 10/16/2023 in #help
❔ OnActionExecuted exception filter runs before exception is thrown and is never called
I'm having a bit of an issue where I'm following the guide from https://learn.microsoft.com/en-us/aspnet/core/web-api/handle-errors?view=aspnetcore-7.0#use-exceptions-to-modify-the-response The goal is to modify the status code when an exception is thrown, I know there are alternative ways to do this, but this is the most straightforward. I already have an expected exception, I built the filter, then deployed it onto builder.Services.AddControllers options.Filters, but it doesn't quite work as expected. When using the debugger I noticed that the onActionExecuted is running before the exception is thrown. The exception then continues, gets thrown, but then the status code is never changed. This was how my original implementation was supposed to behave, but after just trying to copy/paste the exact example from the docs, it didn't work either. Could someone lead me in the right direction on figuring out why OnActionExecuted is not running for when the exception is thrown? There is one thing to keep in mind, the app is very monorepo like, with many sub-repositories. The startup is in /api & the exception and exception filter are declared, but used in /services. But I don't know why this would cause any issues.
26 replies