Closed jmichaelbrown closed 6 years ago
Make sure you specify your contentGenerator Func<TEx, string> argument in .To.
Ex:
.Map<Exception>
.To(HttpStatusCode.InternalServerError, "Operation Canceled", ex => ex.Message)
vs
.Map<Exception>
.To(HttpStatusCode.InternalServerError, "Operation Canceled", ex => JsonConvert.Serialize(ex), "application/json")
.To will just write whatever you return from the contentGenerator, so you have total control over errorFormat
@jmichaelbrown Could you also put a breakpoint in the contentGenerator to make sure you hit it? Because depending on what you are running down-stream (WebApi, WebApi2, Nancy) they often try to swallow the exceptions and write them out to the HTTP stream themself. You will need to use our adapters to hook in, there is currently one for WebApi2. Check the readme for installation guidelines.
Sorry for the delay, I am just now circling back around to this. By adapter I am assuming you mean app.UseFriendlyExceptions(this.GetFriendlyExceptions(), new[] { new WebApi2ExceptionProvider() }); config.Services.Replace(typeof(IExceptionHandler), new WebApi2ExceptionHandler(this.GetFriendlyExceptions()));
I had already done this, however It's still not working, I would like to figure out what's going on here in case anyone else runs into the same issue. I have located what I believe is your "contentGenerator" Is there any particular area I need to check for... like public ITransformsMap? Because it is hitting this
Did you make sure you apply before the rest of your middlewares?
// Use FriendlyExceptions before your other middlewares
app.UseFriendlyExceptions(GetFriendlyExceptions(), new [] {new WebApi2ExceptionProvider()});
// mvc and stuff
Seems to be functioning fine, TransformException is adding correct contenttype, statuscode etc but client always receives stack trace with none of the desired data and no json.
What am I doing wrong?