-
-
Notifications
You must be signed in to change notification settings - Fork 800
Closed
Feature
Copy link
Labels
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Product
Hot Chocolate
Describe the bug
When using type converters, if the type converter fails then the root cause of the failure is lost and can't be used by the error filter.
The exception is a NotSupportedException but the inner exception is null. The resulting error message is the very generic and unhelpful "Unable to convert type from 'x' to 'y'".
One use case where we would find the route cause useful is within our IError filter where we could check for the inner exception type and then change the error message to something more meaningful or change the error code.
services
.AddGraphQLServer()
.AddTypeConverter<T1, T2>(source => throw new CustomException("I want to use this in the error filter below"))
.AddErrorFilter<MyErrorErrorFilter>();
public class MyErrorErrorFilter : IErrorFilter {
public IError OnError(IError error)
{
if (error.Exception is NotSupportedException { InnerException: CustomException } custom )
{
// do something with the custom exception
}
return error;
}
}Steps to reproduce
- Add a type converter which throws an exception
- e.g.
.AddTypeConverter<T1, T2>(source => throw new CustomException("not good")) - Add an IErrorFilter which tries to use the root cause exception
- Observe that the
NotSupportedExceptiondoes not contain the CustomException in the inner exception property
Relevant log output
None.Additional Context?
I have a PR in progress which contains changes isolated to the DefaultTypeConverter to include the inner exception.
If you give me the thumbs up on this issue I'll try to finish it off ASAP.
Version
13.0.5