graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Being able to log errors in Error middleware

Open oysandvik94 opened this issue 3 years ago • 5 comments

Is your feature request related to a problem?

I'm using Mutation Conventions to handle errors by decorating my mutations with [Error(typeof(ValidationException))]. This works well by handling errors for me and I'm able to retrieve the error in the payload just fine. However I want to catch these errors somewhere so I can log them. I tried using IErrorFilter, but it doesn't catch errors when they are defined with the annotation. I also tried using ExecutionDiagnosticEventListener, but didn't find any events that listened to it.

The solution you'd like

Probably a method in ExecutionDiagnosticEventListener that could be overridden to catch the error message for errors, and be able to inject my logger and log them.

Product

Hot Chocolate

oysandvik94 avatar Sep 22 '22 08:09 oysandvik94

@michaelstaib should we add a hook to AddMutationConventions? e.g.

.AddMutationConcentions(options => options.OnError = (sp, errors) => {...})

PascalSenn avatar Sep 22 '22 08:09 PascalSenn

No, that would feel wrong. I will think on this a bit.

michaelstaib avatar Sep 22 '22 10:09 michaelstaib

i guess a mutation diagnostic observer would be a bit overkill

PascalSenn avatar Sep 22 '22 10:09 PascalSenn

Aren't the diagnostic event listeners intended for logging https://chillicream.com/docs/hotchocolate/server/instrumentation ?

resah avatar Dec 21 '22 15:12 resah

@resah no, a this are not really errors ... its schema types and they do not conform with standard GraphQL errors. GraphQL errors = Technical Errors ... these schema types represent domain errors aka business errors.

michaelstaib avatar Jun 28 '24 16:06 michaelstaib