Skip to content

How to log request json body in case of error in Ocelot? #2012

Answered by raman-m
rajeshgithub001 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, but Not all errors will be caught by delegating handler ❗

My recommendation is using PreErrorResponderMiddleware injection. See Middleware Injection.
It requires analysis of Ocelot error codes, with limited access to exception messages.

More advanced approach is replacing IExceptionToErrorMapper object in DI container.

Just define new class inheriting the IExceptionToErrorMapper interface.
Aggregate HttpExceptionToErrorMapper class member as private one.
Decorate behavior of the class or totally replace by new behavior of Decorator pattern.
So, public Error Map(Exception exception) method can be decorated like this:

    public class MyExceptionToErrorMapperDecorator : IExceptionToErr…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@raman-m
Comment options

Answer selected by raman-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Logging Ocelot feature: Logging
3 participants
Converted from issue

This discussion was converted from issue #1218 on March 23, 2024 18:03.