-
Notifications
You must be signed in to change notification settings - Fork 7
WebApi global ExceptionHandler always returns HTML instead of JSON when package SerilogWeb.Classic.WebApi is present in project #16
Comments
Hi Victor, thanks for sharing. It looks very similar to #3 that said :
Would love to be able to fix it. Do you happen to have a minimal repro project that we could use to analyze and try to fix the issue ? We also had a discussion going on there in Thanks |
It reads as something similar, yes. Have to whip up something... |
Minimal project added. The ZIP contains no packages due to issue file upload constraints; you'll have to do a package restore. SerilogWeb.Classic.WebApi is referenced in this project. Requesting /values/5 will throw a IDNotFoundException, which is intercepted by the global exception handler. The handler returns an HTML page when SerilogWeb.Classic.WebApi is referenced. Remove SerilogWeb.Classic.WebApi package from the project and comment out its methods in the code and web.config. Now request /values/5 again, and it will show the exception message in JSON. Good hunting! |
Thanks Victor, that's super useful ! I guess that's the push we needed to start implementing serilog-web/classic#48 and have a less intrusive integration ;) Will keep you posted ! |
Allow to report errors to the module through a less intrusive mechanism - Introduces new extension methods under namespace `SerilogWeb.Classic.Extensions`, mainly to be used by `SerilogWeb.CLassic.WebAPI` for serilog-web/classic-webapi#16 : - `HttpContext.AddSerilogWebError(Exception exception)` / `HttpContextBase.AddSerilogWebError(Exception exception)` - `HttpContext.GetLastSerilogWebError()` / `HttpContextBase.GetLastSerilogWebError()` - bump referenced Serilog version to **v2.7.1** (published 9 month ago) . (v2.8.0 is only a month old, and forcing unnecessary update cold be annoying to end user) - bump package version to **v5.0** . Not really a breaking change but may introduce subtle behavior different when combined with secondary packages (`WebAPI` one)
…to SerilogWeb module Instead rely on ad-hoc extension method that stores it temporarily in HttpContext Related to serilog-web#16 and serilog-web#3
This should now be fixed as per SerilogWeb.Classic.WebApi v4.0.5 . It does at least fix it in your repro 🎉 ! I would love it if you could give it a try and confirm that it solves your issue ! |
Thanks @tsimbalar. I'll check tomorrow morning. |
YES! issue is solved! Thanks a lot! |
Great ! Glad that it fixed it, and sorry for the headaches it might have
caused you...
|
I have an global ExceptionHandler in my WebAPI. Any response from the ExceptionHandler is returned as HTML and not JSON, which is the default content encoding.
Upon removing the SerilogWeb.Classic.WebApi package from the project, responses are no longer in HTML, but now in JSON.
Stackoverflow https://stackoverflow.com/questions/47778018/exceptionhandler-being-called-but-not-returning-json describes the issue and also the culprit, which is SerilogWeb.Classic.WebApi.
The text was updated successfully, but these errors were encountered: