Graphql-dotnet: Possibility to return custom error message

Created on 5 Sep 2017  路  4Comments  路  Source: graphql-dotnet/graphql-dotnet

Hi,

It hase become a must have that i can return meaningful errror messages from the graphql api.

AFAIK this is not yet possible.

I thus recommend following new feature:

  1. Add a new ExceptionClass Called maybe "GraphQL.CustomException"
  2. If this Exception is thrown within a resolver the "Message" of the Exception is displayed
  3. This is going to bypass ExposeExceptions as i expect this to be "expected behaivor" and ur custom message may tells u more than anything else.

So i could simply throw a message inside a resolver like:
thrown new GraphQL.CustomException($"insufficent permissions, und need the permission {RequiredPermission}");

and it will be displayed in errors (without Lines)

@joemcbride What do you think of this feature ? Are u gonna accept a pull request for this ?

question

Most helpful comment

You can add custom errors in the ResolveFieldContext. I think this should solve your issue?

context =>
{
  context.Errors.Add(new ExecutionError("Some Error"));
  return null;
}

All 4 comments

Note: The example maybe isn't good, as permission are handled outside the resolver. But in my case it would be like:

thrown new GraphQL.CustomException($"insufficent licenses, please buy more licenses in the license menu");

You can add custom errors in the ResolveFieldContext. I think this should solve your issue?

context =>
{
  context.Errors.Add(new ExecutionError("Some Error"));
  return null;
}

oops, sorry missed that this was implemented. thanks a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joemcbride picture joemcbride  路  4Comments

csantero picture csantero  路  4Comments

dimortizp picture dimortizp  路  3Comments

Jonatthu picture Jonatthu  路  3Comments

ildoc picture ildoc  路  4Comments